Documentation / zerotal / auth / AuthenticateSessionMiddleware
Class: AuthenticateSessionMiddleware
Defined in: packages/auth/src/AuthenticateSessionMiddleware.ts:34
Binds a session to the user's current password hash so that Auth.logoutOtherDevices (and any password change) can invalidate the user's other sessions without server-side session storage.
On the first authenticated request it snapshots getAuthPassword() into the
session. On later requests it compares the snapshot to the user's current
hash; a mismatch means the password hash changed elsewhere, so this session is
stale and gets torn down (redirect to redirectTo, or 401 for JSON).
Attach it after the auth guard on routes that should be revocable:
Example
Router.group({ middleware: [AuthMiddleware, AuthenticateSessionMiddleware] }, () => {
// ...the bulk of your authenticated routes
});
Extends
Constructors
Constructor
new AuthenticateSessionMiddleware():
AuthenticateSessionMiddleware
Defined in: packages/core/src/middleware/BaseMiddleware.ts:36
Returns
AuthenticateSessionMiddleware
Inherited from
Properties
options
protectedoptions:AuthenticateSessionOptions
Defined in: packages/auth/src/AuthenticateSessionMiddleware.ts:35
Subclasses must declare this with their default option values. TypeScript enforces this at compile time — forgetting it is a type error.
Overrides
Methods
handle()
handle(
http,next):Promise<void|Response>
Defined in: packages/auth/src/AuthenticateSessionMiddleware.ts:37
Parameters
http
next
Returns
Promise<void | Response>
Overrides
with()
staticwith<T,Opts>(this,options): () =>InstanceType<T>
Defined in: packages/core/src/middleware/BaseMiddleware.ts:48
Returns a zero-arg subclass with the given options deep-merged on top of the subclass defaults, usable directly in app.use([...]).
Type Parameters
T
T extends (...args) => BaseMiddleware<any>
Opts
Opts = T extends (...args) => BaseMiddleware<U> ? U : object
Parameters
this
T
options
Partial<Opts>
Returns
() => InstanceType<T>
Inherited from
afterResponse()?
optionalafterResponse(ctx):Promise<void>
Defined in: packages/core/src/middleware/BaseMiddleware.ts:70
Parameters
ctx
Returns
Promise<void>
Inherited from
onError()?
optionalonError(ctx,error):Promise<void>
Defined in: packages/core/src/middleware/BaseMiddleware.ts:71
Parameters
ctx
error
Error
Returns
Promise<void>