62 lines
1.9 KiB
TypeScript
62 lines
1.9 KiB
TypeScript
import { forwardRef, Module } from '@nestjs/common';
|
|
import { AuthService } from './auth.service';
|
|
import { AuthController } from './auth.controller';
|
|
import { DbModule } from 'src/db/db.module';
|
|
import { ConfigService } from '@nestjs/config';
|
|
import { JwtService } from '@nestjs/jwt';
|
|
import { OracleModule } from 'src/oracle/oracle.module';
|
|
import { MailModule } from 'src/mail/mail.module';
|
|
|
|
@Module({
|
|
imports: [DbModule,MailModule, 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],
|
|
}
|
|
],
|
|
controllers: [AuthController],
|
|
exports: [AuthService]
|
|
})
|
|
export class AuthModule { }
|