Arno Kaimbacher
e0ff71b117
All checks were successful
CI Pipeline / japa-tests (push) Successful in 47s
- additional validation rules like 'uniqueArray' - additional Lucid models like BaseModel.ts for filling attributes, Title.ts, Description.ts - npm updates for @adonisjs/core
22 lines
665 B
TypeScript
22 lines
665 B
TypeScript
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
|
|
|
|
/**
|
|
* 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 }: HttpContextContract, 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();
|
|
}
|
|
}
|