This repository has been archived on 2024-10-12. You can view files and clone it, but cannot push or open issues or pull requests.
wikipedia-game-solver/apps/api/app/middleware/auth_middleware.ts
Théo LUDWIG 20ab889cf8
All checks were successful
Chromatic / chromatic (push) Successful in 2m3s
CI / ci (push) Successful in 4m16s
CI / commitlint (push) Successful in 14s
chore: improve type safety Tuyau
2024-08-18 01:31:02 +01:00

27 lines
689 B
TypeScript

import type { Authenticators } from "@adonisjs/auth/types"
import type { HttpContext } from "@adonisjs/core/http"
import type { NextFn } from "@adonisjs/core/types/http"
/**
* Auth middleware is used authenticate HTTP requests and deny access to unauthenticated users.
*/
export default class AuthMiddleware {
/**
* The URL to redirect to, when authentication fails.
*/
redirectTo = "/login"
public async handle(
context: HttpContext,
next: NextFn,
options: {
guards?: Array<keyof Authenticators>
} = {},
): Promise<void> {
await context.auth.authenticateUsing(options.guards, {
loginRoute: this.redirectTo,
})
return next()
}
}