@lygos/nestjs-better-auth
Version:
Better Auth for NestJS
90 lines • 3.09 kB
TypeScript
import type { DynamicModule, MiddlewareConsumer, ModuleMetadata, NestModule, OnModuleInit, Type } from "@nestjs/common";
import { DiscoveryService, HttpAdapterHost, MetadataScanner } from "@nestjs/core";
import type { Auth } from "better-auth";
/**
* Configuration options for the AuthModule
*/
export type AuthModuleOptions = {
disableExceptionFilter?: boolean;
disableTrustedOriginsCors?: boolean;
disableBodyParser?: boolean;
};
/**
* Interface for async configuration of AuthModule
*/
export interface AuthModuleAsyncOptions extends Pick<ModuleMetadata, "imports"> {
/**
* Factory function that returns the auth instance
*/
useFactory: (...args: any[]) => Promise<any> | any;
/**
* Dependencies to inject into the factory function
*/
inject?: any[];
/**
* Configuration options for the module
*/
options?: AuthModuleOptions;
}
/**
* Alternative interface for class-based async configuration
*/
export interface AuthModuleOptionsFactory {
createAuthModuleOptions(): Promise<{
auth: any;
options?: AuthModuleOptions;
}> | {
auth: any;
options?: AuthModuleOptions;
};
}
/**
* Interface for class-based async configuration
*/
export interface AuthModuleAsyncOptionsWithClass extends Pick<ModuleMetadata, "imports"> {
/**
* Class that implements AuthModuleOptionsFactory
*/
useClass: Type<AuthModuleOptionsFactory>;
/**
* Dependencies to inject
*/
inject?: any[];
}
/**
* Union type for all async configuration options
*/
export type AuthModuleAsyncConfig = AuthModuleAsyncOptions | AuthModuleAsyncOptionsWithClass;
/**
* NestJS module that integrates the Auth library with NestJS applications.
* Provides authentication middleware, hooks, and exception handling.
*/
export declare class AuthModule implements NestModule, OnModuleInit {
private readonly auth;
private readonly discoveryService;
private readonly metadataScanner;
private readonly adapter;
private readonly options;
private readonly logger;
constructor(auth: Auth, discoveryService: DiscoveryService, metadataScanner: MetadataScanner, adapter: HttpAdapterHost, options: AuthModuleOptions);
onModuleInit(): void;
configure(consumer: MiddlewareConsumer): void;
private setupHooks;
/**
* Static factory method to create and configure the AuthModule.
* @param auth - The Auth instance to use
* @param options - Configuration options for the module
*/
static forRoot(auth: any, options?: AuthModuleOptions): DynamicModule;
/**
* Static factory method to create and configure the AuthModule asynchronously.
* Useful when you need to inject dependencies or fetch configuration from external sources.
* @param asyncOptions - Async configuration options
*/
static forRootAsync(asyncOptions: AuthModuleAsyncConfig): DynamicModule;
/**
* Creates the async providers for the AuthModule
*/
private static createAsyncProviders;
}
//# sourceMappingURL=auth-module.d.ts.map