mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-11 08:43:04 +00:00
22 lines
525 B
TypeScript
22 lines
525 B
TypeScript
import { getRoute } from '#lib/route_helper';
|
|
import type { Authenticators } from '@adonisjs/auth/types';
|
|
import type { HttpContext } from '@adonisjs/core/http';
|
|
import type { NextFn } from '@adonisjs/core/types/http';
|
|
|
|
export default class AuthMiddleware {
|
|
redirectTo = getRoute('auth').path;
|
|
|
|
async handle(
|
|
ctx: HttpContext,
|
|
next: NextFn,
|
|
options: {
|
|
guards?: (keyof Authenticators)[];
|
|
} = {}
|
|
) {
|
|
await ctx.auth.authenticateUsing(options.guards, {
|
|
loginRoute: this.redirectTo,
|
|
});
|
|
return next();
|
|
}
|
|
}
|