Appearance
Auth Config
The Authentication Configuration (AuthConfig) provides a streamlined approach for configuring authentication-related settings in your application (AuthNModule). It simplifies the process of managing settings like registration approval processes, allowing you to tailor the user authentication experience to meet your application's requirements.
AuthConfig can be integrated with authentication modules, offering customizable options to control and interact with authentication processes effectively.
Environment Variables in AuthConfig:
AuthConfig does not directly utilize environment variables for configuration. Instead, it is configured programmatically with options passed during its creation. However, you can adapt your environment variables to influence these options if needed.
How to Create AuthConfig:
Creating an AuthConfig involves calling the createAuthConfig function with optional settings. Here's how you can do it:
ts
// src/config/index.ts
import { createAuthConfig } from '@deep/nest-kit/dist/configs';
// Optional configuration options can be passed here
export const AuthConfig = createAuthConfig({
waitingForApprovalAfterRegistration: true // or false, depending on your needs
});This example demonstrates initializing the AuthConfig with an option that dictates whether user registrations require approval before activation.
How to Inject AuthConfig into a Service or Controller:
Injecting AuthConfig into your services or controllers allows you to access its settings wherever needed. This is achieved using the @Inject() decorator provided by NestJS. Here's a step-by-step guide to doing so:
Import Necessary Modules:
Begin by importing
Injectfrom@nestjs/common, which is necessary for the injection process.tsimport { Inject } from '@nestjs/common';Import Your
AuthConfig:Ensure that your
AuthConfigis imported from where it is defined.tsimport { AuthConfig } from './config'; // Adjust the path as neededInject
AuthConfigUsing the@Inject()Decorator:Now, you can use the
@Inject()decorator to injectAuthConfiginto your class. Here's an example for a service class:ts@Injectable() export class YourAuthService { constructor( @Inject(AuthConfig.KEY) private authConfig: ConfigType<keyof AuthConfig>, ) {} // Here you can access this.authConfig... }