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.
21 lines • 902 B
text/typescript
/**
* Retrieves a session value from the request's session object based on the provided key.
* If the session object and the specific session key exist and are of the expected type,
* the value is returned. Otherwise, `null` is returned.
*
* @function
* @param {Record<string, any>} req - The request object, which contains the session data.
* @param {string} where - The key for which the session value is being retrieved.
*
* @returns {string|null} The session value associated with the provided key, or `null` if it doesn't exist or isn't valid.
*
* @example
* const userToken = cookieSession(req, 'authToken');
* if (userToken) {
* console.log('Session token:', userToken);
* } else {
* console.log('No valid token in session');
* }
*/
export default function cookieSession(req: Record<string, any>, where: string): string | null;
//# sourceMappingURL=cookie-session.d.mts.map