mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-08 14:43:24 +00:00
29 lines
693 B
TypeScript
29 lines
693 B
TypeScript
import type { Authenticators } from '@adonisjs/auth/types';
|
|
import type { HttpContext } from '@adonisjs/core/http';
|
|
import type { NextFn } from '@adonisjs/core/types/http';
|
|
import { route } from '@izzyjs/route/client';
|
|
|
|
/**
|
|
* 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 = route('auth').path;
|
|
|
|
async handle(
|
|
ctx: HttpContext,
|
|
next: NextFn,
|
|
options: {
|
|
guards?: (keyof Authenticators)[];
|
|
} = {}
|
|
) {
|
|
await ctx.auth.authenticateUsing(options.guards, {
|
|
loginRoute: this.redirectTo,
|
|
});
|
|
return next();
|
|
}
|
|
}
|