@analog-tools/auth
Version:
Authentication module for AnalogJS applications
35 lines (34 loc) • 1.52 kB
TypeScript
import { H3Event } from 'h3';
import { AuthSessionData, SessionWithSave, SessionWithHandler } from '../types/auth-session.types';
import { SessionStorageConfig } from '../types/auth.types';
export declare class SessionService {
private readonly storageConfig;
private readonly sessionSecret;
private store;
private logger;
constructor(config: SessionStorageConfig);
/**
* Resolve and validate the session signing secret. A missing secret is a
* fatal misconfiguration: the library used to silently fall back to a shared,
* source-visible default, which let anyone forge session cookies. A non-empty
* array of secrets is accepted to support key rotation (first entry signs,
* the rest still verify).
*/
private resolveSessionSecret;
initSession(event: H3Event): Promise<void>;
/**
* Get a session by session ID
* @param sessionId The session ID
* @returns The session object or null if not found
*/
getSession(sessionId: string): Promise<SessionWithSave | null>;
/**
* Get all active sessions from storage
* @returns Array of session objects with update capability
*/
getActiveSessions(): Promise<SessionWithHandler[]>;
destroyAuthSession(event: H3Event): Promise<void>;
getSessionData<T>(event: H3Event, key: keyof AuthSessionData): Promise<T | null>;
setSessionData<T>(event: H3Event, key: keyof AuthSessionData, value: T): Promise<void>;
isValidSession(event: H3Event): Promise<boolean>;
}