@nopwdio/sdk-js
Version:
Nopwd JS SDK
29 lines (28 loc) • 1.41 kB
TypeScript
import { TokenPayload } from "./token.js";
export interface Session {
created_at: number;
created_with: string[];
expires_at: number;
idle_timeout: number;
token: string;
token_payload: TokenPayload;
suggest_passkeys: boolean;
}
/**
* Create a session and replace the current one if exists.
* @param token the access token generated by email or passkey authentication methods.
* @param lifetime the session maximum duration in second. By default 24h.
* @param idleTimeout the session inactivity timeout.
* @returns the session object.
* @throws {AbortError} when the authentication flow has been canceled (using signal)
* @throws {UnexpectedError} when an unexpected error occured
* @throws {MissingTokenError} if the token is not defined
* @throws {NetworkError} when a connection error occured
* @throws {InvalidTokenError} when the access token is malformed or expired
*/
export declare const create: (token: string, lifetime?: number, idleTimeout?: number) => Promise<Session>;
export declare const get: () => Promise<Session | null | undefined>;
export declare const revoke: () => Promise<void>;
export type SessionStateListener = (session: Session | null | undefined) => void;
export declare const addSessionStateChanged: (listener: SessionStateListener) => Promise<void>;
export declare const removeSessionStateChanged: (listener: SessionStateListener) => void;