/// /// import { IncomingMessage } from 'http'; import { CookieAttributes } from 'js-cookie'; import { FetchConnector } from './connectors/utils'; export declare type CookieOptions = CookieAttributes | ((accessToken?: string) => CookieAttributes); export declare type GetTokens = (req: IncomingMessage) => { refreshToken?: string; accessToken?: string; } | void; export declare type Decode = (accessToken: string) => object | null | void; export interface AuthClientOptions { cookie?: string; cookieOptions?: CookieOptions; decode: Decode; fetchConnector?: FetchConnector; refreshTokenCookie?: string; getTokens?: GetTokens; } export declare class AuthClient { cookie: string; cookieOptions?: CookieOptions; decode: Decode; fetch?: FetchConnector; private refreshTokenCookie?; private getTokens; private clientATFetch?; constructor(options: AuthClientOptions); /** * Returns the accessToken from cookies */ getAccessToken(): string | undefined; /** * Decodes an accessToken and returns his payload or null */ decodeAccessToken(accessToken: string): object | null; /** * Sets an accessToken as a cookie and returns the accessToken */ setAccessToken(accessToken: string): string | undefined; /** * Removes the accessToken from cookies */ removeAccessToken(): void; /** * Logouts the user, this means remove both accessToken and refreshToken from * cookies */ logout(): Promise<{ done: boolean; } | undefined>; /** * Returns a new accessToken * @param req Sending a Request means the token will be created during SSR */ fetchAccessToken(req?: IncomingMessage): Promise; /** * Returns true if a refreshToken cookie is defined */ withRefreshToken(): boolean; /** * Returns the accessToken on SSR from cookies, if no token exists or its * invalid then it will fetch a new accessToken */ private fetchServerToken(req); /** * Returns the accessToken from cookies, if no token exists or its * invalid then it will fetch a new accessToken */ private fetchClientToken(); /** * Verifies and returns an accessToken if it's still valid */ private verifyAccessToken(accessToken); /** * Returns the cookie options that will be used to set an accessToken, * accessToken will be undefined when removing a cookie */ private getCookieOptions(accessToken?); /** * Gets the tokens from a Request */ private _getTokens(req); }