BE/src/auth/auth.module.ts

61 lines
1.8 KiB
TypeScript
Raw Normal View History

2025-07-02 17:37:04 +05:30
import { forwardRef, Module } from '@nestjs/common';
2025-02-24 10:32:41 +05:30
import { AuthService } from './auth.service';
import { AuthController } from './auth.controller';
import { DbModule } from 'src/db/db.module';
2025-07-02 17:37:04 +05:30
import { ConfigService } from '@nestjs/config';
import { JwtService } from '@nestjs/jwt';
import { OracleModule } from 'src/oracle/oracle.module';
2025-02-24 10:32:41 +05:30
@Module({
2025-07-02 17:37:04 +05:30
imports: [DbModule, forwardRef(() => OracleModule)],
providers: [
AuthService,
{
provide: "REGISTER_SIGN_JWT",
useFactory: (config: ConfigService) => {
const base64Key = config.get<string>('JWT_REGISTER_PRIVATE_KEY');
if (!base64Key) {
throw new Error('JWT_REGISTER_PRIVATE_KEY is not defined in the config');
}
const secretKey = Buffer.from(base64Key, 'base64').toString('utf-8');
const expiry = config.get<string>('JWT_REGISTER_EXPIRY');
if (!expiry) {
throw new Error('JWT_REGISTER_PRIVATE_KEY is not defined in the config');
}
return new JwtService({
secret: secretKey,
signOptions: {
expiresIn: expiry,
algorithm: 'ES384'
},
})
},
inject: [ConfigService],
},
{
provide: "REGISTER_VERIFY_JWT",
useFactory: (config: ConfigService) => {
const base64Key = config.get<string>('JWT_REGISTER_PUBLIC_KEY');
if (!base64Key) {
throw new Error('JWT_REGISTER_PRIVATE_KEY is not defined in the config');
}
const secretKey = Buffer.from(base64Key, 'base64').toString('utf-8');
return new JwtService({
secret: secretKey,
verifyOptions: {
algorithms: ['ES384']
}
})
},
inject: [ConfigService],
}
],
2025-02-24 10:32:41 +05:30
controllers: [AuthController],
2025-06-18 17:15:21 +05:30
exports: [AuthService]
2025-02-24 10:32:41 +05:30
})
2025-06-18 17:15:21 +05:30
export class AuthModule { }