UNPKG

@duongtrungnguyen/next-helper

Version:
46 lines 2.22 kB
import type { User, AuthTokens, AuthResult } from "./types"; /** * Sets authentication cookies for access and refresh tokens. * * @param {AuthTokens} tokens - The authentication tokens containing access and refresh tokens. * @returns {Promise<void>} A promise that resolves when the cookies are set. * * @throws {Error} If there is an issue setting the cookies. */ export declare function setAuthCookies(tokens: AuthTokens): Promise<void>; /** * Clears the authentication cookies from the cookie store. * * This function deletes the access token and refresh token cookies * based on the configuration provided by `getConfig()`. * * @returns {Promise<void>} A promise that resolves when the cookies have been deleted. */ export declare function clearAuthCookies(): Promise<void>; /** * Retrieves the current user based on the access token stored in cookies. * * @returns {Promise<User | null>} A promise that resolves to the current user object if the access token is valid, or null if the access token is missing or invalid. * * @throws Will log an error message to the console if there is an issue with fetching the current user. */ export declare function getCurrentUser(): Promise<User | null>; /** * Refreshes the access token by making a POST request to the refresh endpoint. * * This function retrieves the refresh token from cookies and sends it in the * Authorization header to get new tokens, which are then stored in cookies. * * @returns {Promise<boolean>} A promise that resolves to `true` if the token was successfully refreshed, or `false` otherwise. * * @throws Will log an error message to the console if an error occurs during the process. */ export declare function refreshAccessToken(): Promise<boolean>; /** * Authenticates the current user based on a provided condition. * * @param condition - A function that takes a user object and returns a boolean indicating whether the user meets the condition. Defaults to a function that always returns true. * @returns A promise that resolves to an AuthResult object containing the user if the condition is met, or null otherwise. */ export declare function auth(): Promise<AuthResult>; //# sourceMappingURL=server.d.ts.map