@analog-tools/auth
Version:
Authentication module for AnalogJS applications
50 lines (49 loc) • 1.66 kB
TypeScript
/**
* Auth session data interface for strongly-typed session operations
*/
export interface AuthSessionData {
/** Authentication data */
auth?: {
/** Whether the user is authenticated */
isAuthenticated: boolean;
/** OAuth access token */
accessToken?: string;
/** OAuth ID token */
idToken?: string;
/** OAuth refresh token */
refreshToken?: string;
/** Timestamp when the token expires */
expiresAt?: number;
/** User info from OAuth provider */
userInfo?: Record<string, unknown>;
};
/** User data from the database */
user?: Record<string, unknown> | null;
/** State parameter for CSRF protection */
state?: string;
/** PKCE code verifier (transient, cleared after the callback) */
codeVerifier?: string;
/** OIDC nonce for ID-token replay protection (transient) */
nonce?: string;
/** Redirect URL after authentication */
redirectUrl?: string;
/** Any additional session data */
[key: string]: unknown;
}
export interface SessionWithSave {
/** Session ID */
id: string;
/** Session data */
data: AuthSessionData;
/** Save session data */
save: () => Promise<void>;
}
/**
* Session handler interface for working with session operations
*/
export interface SessionWithHandler extends SessionWithSave {
/** Update session data immutably */
update: (updater: (data: AuthSessionData) => AuthSessionData) => void;
/** Re-read this session's current data directly from storage, bypassing the in-memory snapshot */
refetch: () => Promise<AuthSessionData | null>;
}