UNPKG

@adonisjs/auth

Version:

Official authentication provider for Adonis framework

58 lines (57 loc) 1.94 kB
import type { HttpContext } from '@adonisjs/core/http'; import type { GuardFactory } from './types.ts'; import { Authenticator } from './authenticator.ts'; import { AuthenticatorClient } from './authenticator_client.ts'; /** * Auth manager exposes the API to register and manage authentication * guards from the config */ export declare class AuthManager<KnownGuards extends Record<string, GuardFactory>> { config: { default: keyof KnownGuards; guards: KnownGuards; }; /** * Name of the default guard configured in the auth configuration * * @example * const manager = new AuthManager({ default: 'web', guards: {} }) * console.log(manager.defaultGuard) // 'web' */ get defaultGuard(): keyof KnownGuards; /** * Creates a new AuthManager instance * * @param config - Configuration object containing default guard and available guards * * @example * const manager = new AuthManager({ * default: 'web', * guards: { web: sessionGuard, api: tokenGuard } * }) */ constructor(config: { default: keyof KnownGuards; guards: KnownGuards; }); /** * Create an authenticator for a given HTTP request. The authenticator * is used to authenticate incoming HTTP requests * * @param ctx - The HTTP context for the current request * * @example * const authenticator = manager.createAuthenticator(ctx) * const user = await authenticator.authenticate() */ createAuthenticator(ctx: HttpContext): Authenticator<KnownGuards>; /** * Creates an instance of the authenticator client. The client is * used to setup authentication state during testing. * * @example * const client = manager.createAuthenticatorClient() * const guard = client.use('session') */ createAuthenticatorClient(): AuthenticatorClient<KnownGuards>; }