@adonisjs/auth
Version:
Official authentication provider for Adonis framework
43 lines (42 loc) • 1.94 kB
TypeScript
import type { Hash, HashManager } from '@adonisjs/core/hash';
import { type BaseModel } from '@adonisjs/lucid/orm';
import type { NormalizeConstructor } from '@adonisjs/core/types/helpers';
type UserWithUserFinderRow = {
verifyPassword(plainPassword: string): Promise<boolean>;
validatePassword(plainPassword: string, passwordFieldName?: string): Promise<void>;
};
type UserWithUserFinderClass<Model extends NormalizeConstructor<typeof BaseModel> = NormalizeConstructor<typeof BaseModel>> = Model & {
hashPassword<T extends UserWithUserFinderClass>(this: T, user: InstanceType<T>): Promise<void>;
findForAuth<T extends UserWithUserFinderClass>(this: T, uids: string[], value: string): Promise<InstanceType<T> | null>;
verifyCredentials<T extends UserWithUserFinderClass>(this: T, uid: string, password: string): Promise<InstanceType<T>>;
new (...args: any[]): UserWithUserFinderRow;
};
/**
* Mixing to add user lookup and password verification methods
* on a model.
*
* Under the hood, this mixin defines following methods and hooks
*
* - beforeSave hook to hash user password
* - findForAuth method to find a user during authentication
* - verifyCredentials method to verify user credentials and prevent
* timing attacks.
*
* @param hash - Function that returns a Hash instance for password hashing
* @param options - Configuration options with uids and password column name
*
* @example
* import { withAuthFinder } from '@adonisjs/auth/mixins/lucid'
*
* class User extends withAuthFinder(hash, {
* uids: ['email', 'username'],
* passwordColumnName: 'password'
* })(BaseModel) {
* // User model implementation
* }
*/
export declare function withAuthFinder(hash: (() => Hash) | HashManager<any>, options?: {
uids?: string[];
passwordColumnName?: string;
}): <Model extends NormalizeConstructor<typeof BaseModel>>(superclass: Model) => UserWithUserFinderClass<Model>;
export {};