UNPKG

@adonisjs/auth

Version:

Official authentication provider for Adonis framework

41 lines (40 loc) 1.27 kB
import { t as AuthManager } from "../auth_manager-Cp_ofh4p.js"; import { RuntimeException } from "@adonisjs/core/exceptions"; import { configProvider } from "@adonisjs/core"; //#region providers/auth_provider.ts /** * The AuthProvider service provider registers the auth manager * with the IoC container as a singleton * * @example * // The auth manager is automatically registered and can be injected * container.use('auth.manager') */ var AuthProvider = class { /** * Creates a new AuthProvider instance * * @param app - The application service instance */ constructor(app) { this.app = app; } /** * Registers the auth manager as a singleton service * in the IoC container * * @example * // This method is called automatically by AdonisJS * // The auth manager becomes available as 'auth.manager' */ register() { this.app.container.singleton("auth.manager", async () => { const authConfigProvider = this.app.config.get("auth"); const config = await configProvider.resolve(this.app, authConfigProvider); if (!config) throw new RuntimeException("Invalid config exported from \"config/auth.ts\" file. Make sure to use the defineConfig method"); return new AuthManager(config); }); } }; //#endregion export { AuthProvider as default };