forked from MentoNest/SkillSync_Server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjwt.config.ts
More file actions
26 lines (23 loc) · 815 Bytes
/
Copy pathjwt.config.ts
File metadata and controls
26 lines (23 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { ConfigModule, ConfigService } from '@nestjs/config';
import { JwtModuleOptions } from '@nestjs/jwt';
import { Algorithm } from 'jsonwebtoken';
export const jwtModuleConfig = {
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (config: ConfigService): JwtModuleOptions => {
const algorithm = config.get<Algorithm>('JWT_ALGORITHM', 'HS256');
if (algorithm === 'RS256') {
return {
privateKey: config.get<string>('JWT_PRIVATE_KEY'),
publicKey: config.get<string>('JWT_PUBLIC_KEY'),
signOptions: { algorithm },
verifyOptions: { algorithms: [algorithm] },
};
}
return {
secret: config.get<string>('JWT_SECRET', 'dev-secret'),
signOptions: { algorithm },
verifyOptions: { algorithms: [algorithm] },
};
},
};