function authMiddleware
authMiddleware<R extends string>(
ctx: AuthContext<R>,
next: Next
): Promise<void>

Requires a valid session token in the Authorization header, and puts its payload in ctx.state.user for the rest of the route.

Type Parameters

R extends string

Parameters

next: Next

Return Type

Promise<void>

Throws

APIException

401 when the token is missing or invalid.

Usage

import { authMiddleware } from "api/middleware/auth.ts";