tethys.backend/app/middleware/auth_middleware.ts
Arno Kaimbacher a29865b781
Some checks failed
CI Pipeline / japa-tests (push) Failing after 58s
- renamings to the new naming convetion for adonisjs version 6
- npm updates
2024-04-29 11:25:50 +02:00

25 lines
651 B
TypeScript

import type { HttpContext } from '@adonisjs/core/http'
import type { NextFn } from '@adonisjs/core/types/http'
import type { Authenticators } from '@adonisjs/auth/types'
/**
* 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 = '/app/login'
async handle(
ctx: HttpContext,
next: NextFn,
options: {
guards?: (keyof Authenticators)[]
} = {}
) {
await ctx.auth.authenticateUsing(options.guards, { loginRoute: this.redirectTo })
return next()
}
}