This repository has been archived on 2024-11-10. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
enzos-events/app/Middleware/SilentAuth.ts
Sockenklaus a52c0143df Added database, orm, auth modules
added db migrations for users and initial data
added first controllers
added auth middleware
added rest routes and controller stub
...
2023-07-03 16:24:19 +02:00

22 lines
628 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()
}
}