UNPKG

@adonisjs/auth

Version:

Official authentication provider for Adonis framework

45 lines (44 loc) 1.51 kB
import type { GuardFactory } from './types.ts'; /** * Authenticator client is used to create guard instances for testing. * It passes a fake HTTPContext to the guards, so make sure to not * call server side APIs that might be relying on a real * HTTPContext instance. */ export declare class AuthenticatorClient<KnownGuards extends Record<string, GuardFactory>> { #private; /** * Name of the default guard configured in the auth configuration * * @example * const client = new AuthenticatorClient({ default: 'web', guards: {} }) * console.log(client.defaultGuard) // 'web' */ get defaultGuard(): keyof KnownGuards; /** * Creates a new AuthenticatorClient instance for testing * * @param config - Configuration object containing default guard and available guards * * @example * const client = new AuthenticatorClient({ * default: 'web', * guards: { web: sessionGuard } * }) */ constructor(config: { default: keyof KnownGuards; guards: KnownGuards; }); /** * Returns an instance of a known guard. Guards instances are * cached during the lifecycle of an HTTP request. * * @param guard - Optional guard name. Uses default guard if not provided * * @example * const sessionGuard = client.use('session') * const defaultGuard = client.use() */ use<Guard extends keyof KnownGuards>(guard?: Guard): ReturnType<KnownGuards[Guard]>; }