@adonisjs/auth
Version:
Official authentication provider for Adonis framework
72 lines (71 loc) • 2.43 kB
TypeScript
import { PROVIDER_REAL_USER } from '../../../src/symbols.ts';
import type { BasicAuthGuardUser, LucidAuthenticatable, BasicAuthUserProviderContract, BasicAuthLucidUserProviderOptions } from '../types.ts';
/**
* Uses a Lucid model to verify access tokens and find a user during
* authentication
*
* @template UserModel - The Lucid model representing the user
*
* @example
* const userProvider = new BasicAuthLucidUserProvider({
* model: () => import('#models/user')
* })
*/
export declare class BasicAuthLucidUserProvider<UserModel extends LucidAuthenticatable> implements BasicAuthUserProviderContract<InstanceType<UserModel>> {
/**
* Lucid provider options
*/
protected options: BasicAuthLucidUserProviderOptions<UserModel>;
[PROVIDER_REAL_USER]: InstanceType<UserModel>;
/**
* Reference to the lazily imported model
*/
protected model?: UserModel;
/**
* Creates a new BasicAuthLucidUserProvider instance
*
* @param options - Configuration options for the user provider
*
* @example
* const provider = new BasicAuthLucidUserProvider({
* model: () => import('#models/user')
* })
*/
constructor(
/**
* Lucid provider options
*/
options: BasicAuthLucidUserProviderOptions<UserModel>);
/**
* Imports the model from the provider, returns and caches it
* for further operations.
*
* @example
* const UserModel = await provider.getModel()
* const user = await UserModel.find(1)
*/
protected getModel(): Promise<UserModel>;
/**
* Creates an adapter user for the guard
*
* @param user - The user model instance
*
* @example
* const guardUser = await provider.createUserForGuard(user)
* console.log('User ID:', guardUser.getId())
*/
createUserForGuard(user: InstanceType<UserModel>): Promise<BasicAuthGuardUser<InstanceType<UserModel>>>;
/**
* Verifies credentials using the underlying model
*
* @param uid - The username or user identifier
* @param password - The password to verify
*
* @example
* const guardUser = await provider.verifyCredentials('user@example.com', 'secret')
* if (guardUser) {
* console.log('Valid credentials')
* }
*/
verifyCredentials(uid: string, password: string): Promise<BasicAuthGuardUser<InstanceType<UserModel>> | null>;
}