tiny-essentials
Version:
Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.
57 lines • 2.3 kB
text/typescript
export default AuthSystem;
/**
* Class representing an authentication system for generating session cookies.
*
* The AuthSystem handles checking the authentication time and generating session cookies based on
* ID token verification. It supports custom time checking and cookie generation logic.
*
* @class AuthSystem
*/
declare class AuthSystem {
auth_time: number;
default: {
/**
* Checks whether the authentication time is within the last 5 minutes.
*
* @param {Object} decodedIdToken - The decoded ID token object.
* @param {number} decodedIdToken.auth_time - The authentication time from the ID token.
* @returns {boolean} Returns `true` if the authentication time is within the last 5 minutes.
*/
checkAuthTime: (decodedIdToken: {
auth_time: number;
}) => boolean;
/**
* Generates the session cookie expiration time ({this.auth_time} days by default).
*
* @returns {number} Returns the expiration time in milliseconds (5 days).
*/
cookieTimeGenerator: () => number;
};
checkAuthTime: (decodedIdToken: {
auth_time: number;
}) => boolean;
cookieTimeGenerator: () => number;
/**
* Sets a custom callback to check authentication time.
*
* @param {Function} callback - The callback function to validate authentication time.
* @returns {void}
*/
setCookieTimeGenerator(callback: Function): void;
/**
* Sets a custom callback to generate the cookie expiration time.
*
* @param {Function} callback - The callback function to generate cookie expiration time.
* @returns {void}
*/
setCheckAuthTime(callback: Function): void;
/**
* Generates a session cookie for the user after verifying the ID token.
*
* @param {Record<string, any>} auth - The authentication object used to verify the ID token and create session cookies.
* @param {string} token - The ID token of the authenticated user.
* @returns {Promise<string>} A promise that resolves with the session cookie or rejects with an error.
*/
genCookieSession(auth: Record<string, any>, token: string): Promise<string>;
}
//# sourceMappingURL=cookieSession.d.mts.map