@adonisjs/auth
Version:
Official authentication provider for Adonis framework
42 lines (41 loc) • 1.66 kB
TypeScript
import type { PluginFn } from '@japa/runner/types';
import type { ApplicationService } from '@adonisjs/core/types';
import type { Authenticators, GuardContract, GuardFactory } from '../../types.ts';
declare module '@japa/api-client' {
interface ApiRequest {
authData: {
guard: keyof Authenticators | '__default__';
args: [unknown, ...any[]];
};
/**
* Login a user using the default authentication guard
* when making an API call
*/
loginAs(...args: {
[K in keyof Authenticators]: Authenticators[K] extends GuardFactory ? ReturnType<Authenticators[K]> extends GuardContract<unknown> ? Parameters<ReturnType<Authenticators[K]>['authenticateAsClient']> : never : never;
}[keyof Authenticators]): this;
/**
* Define the authentication guard for login
*/
withGuard<K extends keyof Authenticators, Self extends ApiRequest>(this: Self, guard: K): {
/**
* Login a user using a specific auth guard
*/
loginAs(...args: ReturnType<Authenticators[K]> extends GuardContract<any> ? Parameters<ReturnType<Authenticators[K]>['authenticateAsClient']> : never): Self;
};
}
}
/**
* Auth API client to authenticate users when making
* HTTP requests using the Japa API client
*
* @param app - The AdonisJS application service instance
*
* @example
* import { authApiClient } from '@adonisjs/auth/plugins/japa/api_client'
*
* export const plugins: PluginFn[] = [
* authApiClient(app)
* ]
*/
export declare const authApiClient: (app: ApplicationService) => PluginFn;