| Total Complexity | 2 |
| Complexity/F | 1 |
| Lines of Code | 22 |
| Function Count | 2 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext' |
||
| 2 | |||
| 3 | /** |
||
| 4 | * Silent auth middleware can be used as a global middleware to silent check |
||
| 5 | * if the user is logged-in or not. |
||
| 6 | * |
||
| 7 | * The request continues as usual, even when the user is not logged-in. |
||
| 8 | */ |
||
| 9 | export default class SilentAuthMiddleware { |
||
| 10 | /** |
||
| 11 | * Handle request |
||
| 12 | */ |
||
| 13 | public async handle({ auth }: HttpContextContract, next: () => Promise<void>) { |
||
| 14 | /** |
||
| 15 | * Check if user is logged-in or not. If yes, then `ctx.auth.user` will be |
||
| 16 | * set to the instance of the currently logged in user. |
||
| 17 | */ |
||
| 18 | await auth.check() |
||
| 19 | await next() |
||
| 20 | } |
||
| 21 | } |
||
| 22 |