2023-06-22 15:20:04 +00:00
|
|
|
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
|
2023-03-03 15:54:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 {
|
|
|
|
/**
|
2023-06-22 15:20:04 +00:00
|
|
|
* Handle request
|
2023-03-03 15:54:28 +00:00
|
|
|
*/
|
2023-06-22 15:20:04 +00:00
|
|
|
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();
|
|
|
|
}
|
2023-03-03 15:54:28 +00:00
|
|
|
}
|