@nhost/nhost-js
Version:
Nhost JavaScript SDK
62 lines • 2.26 kB
TypeScript
/**
* Storage implementations for session persistence in different environments.
*
* This module provides different storage adapters for persisting authentication sessions
* across page reloads and browser sessions.
*/
import type { Session as AuthSession } from '../auth';
import { type StoredSession } from './session';
import { type SessionStorageBackend } from './storageBackend';
/**
* Callback function type for session change subscriptions
*/
export type SessionChangeCallback = (session: StoredSession | null) => void;
/**
* A wrapper around any SessionStorageInterface implementation that adds
* the ability to subscribe to session changes.
*/
export declare class SessionStorage {
private readonly storage;
private subscribers;
/**
* Creates a new SessionStorage instance
* @param storage - The underlying storage implementation to use
*/
constructor(storage: SessionStorageBackend);
/**
* Gets the session from the underlying storage
* @returns The stored session or null if not found
*/
get(): StoredSession | null;
/**
* Sets the session in the underlying storage and notifies subscribers
* @param value - The session to store
*/
set(value: AuthSession): void;
/**
* Removes the session from the underlying storage and notifies subscribers
*/
remove(): void;
/**
* Subscribe to session changes
* @param callback - Function that will be called when the session changes
* @returns An unsubscribe function to remove this subscription
*/
onChange(callback: SessionChangeCallback): () => void;
/**
* Notify all subscribers of a session change
* @param session - The new session value or null if removed
*/
private notifySubscribers;
}
/**
* Detects the best available storage implementation for the current environment.
*
* The detection process follows this order:
* 1. Try to use localStorage if we're in a browser environment
* 2. Fall back to in-memory storage if localStorage isn't available
*
* @returns The best available storage implementation as a SessionStorageBackend
*/
export declare const detectStorage: () => SessionStorageBackend;
//# sourceMappingURL=storage.d.ts.map