Skip to main content
zerotal

Documentation


Documentation / @zerotal/auth / AuthenticateSessionMiddleware

Class: AuthenticateSessionMiddleware

Defined in: 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: core/src/middleware/BaseMiddleware.ts:36

Returns

AuthenticateSessionMiddleware

Inherited from

BaseMiddleware.constructor

Properties

options

protected options: AuthenticateSessionOptions

Defined in: 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

BaseMiddleware.options

Methods

handle()

handle(http, next): Promise<void | Response>

Defined in: auth/src/AuthenticateSessionMiddleware.ts:37

Parameters

http

HttpContext

next

NextFn

Returns

Promise<void | Response>

Overrides

BaseMiddleware.handle


with()

static with<T, Opts>(this, options): () => InstanceType<T>

Defined in: 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

BaseMiddleware.with


afterResponse()?

optional afterResponse(ctx): Promise<void>

Defined in: core/src/middleware/BaseMiddleware.ts:70

Parameters

ctx

HttpContext

Returns

Promise<void>

Inherited from

BaseMiddleware.afterResponse


onError()?

optional onError(ctx, error): Promise<void>

Defined in: core/src/middleware/BaseMiddleware.ts:71

Parameters

ctx

HttpContext

error

Error

Returns

Promise<void>

Inherited from

BaseMiddleware.onError