tethys.backend/app/middleware/SilentAuth.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

22 lines
640 B
TypeScript

import type { HttpContext } from '@adonisjs/core/http';
/**
* Silent auth middleware can be used as a global middleware to silent check
* if the user is logged-in or not.
*
* The request continues as usual, even when the user is not logged-in.
*/
export default class SilentAuthMiddleware {
/**
* Handle request
*/
public async handle({ auth }: HttpContext, next: () => Promise<void>) {
/**
* Check if user is logged-in or not. If yes, then `ctx.auth.user` will be
* set to the instance of the currently logged in user.
*/
await auth.check();
await next();
}
}