AuthRequest

invalidate()#

Invalidates the internal cache for AuthRequest.validate() and AuthRequest.validateBearerToken().

const invalidate: () => void;

setSession()#

Sets a session cookie. Providing null will create a blank session cookie that will delete the current one.

const setSession: (session: Session | null) => void;
Parameters#
nametypedescription
sessionSession| nullSession to store

Example#

import { auth } from "./lucia.js";

const authRequest = auth.handleRequest();
authRequest.setSession(session);
authRequest.setSession(null); // delete session cookie

validate()#

Validates the session cookie using Auth.validateSession(). This resets the session if its idle, and returns the validated session if the cookie is valid, or null if not, Additionally, when a session is reset, a new session cookie is set.

By default, this method will also return null if the request is from an untrusted origin.

const validate: () => Promise<Session | null>;
Returns#
typedescription
SessionThe validated session
nullThe session stored is invalid

Example#

import { auth } from "./lucia.js";

const authRequest = auth.handleRequest();
const session = await authRequest.validate();
if (session) {
	// valid session
}

validateBearerToken()#

Validates the session cookie using [Auth.validateSession()](/reference/lucia/interfaces/auth#validatesession. This resets the session if its idle, and returns the validated session if the token is valid, or null if not,

const validateBearerToken: () => Promise<Session | null>;
Returns#
typedescription
SessionThe validated session
nullThe session is invalid

Example#

import { auth } from "./lucia.js";

const authRequest = auth.handleRequest();
const session = await authRequest.validateBearerToken();
if (session) {
	// valid session
}