-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.ts
More file actions
44 lines (35 loc) · 1.27 KB
/
index.ts
File metadata and controls
44 lines (35 loc) · 1.27 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { Inject, Injectable, Logger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { PassportStrategy } from '@nestjs/passport';
import strategy from './Strategy';
import { DiscordPermissionScope } from './types';
@Injectable()
export class DiscordStrategy extends PassportStrategy(strategy, 'discord') {
private static logger = new Logger(DiscordStrategy.name);
constructor(
@Inject(ConfigService)
configService: ConfigService,
) {
const DISCORD_CLIENT_ID =
configService.getOrThrow<string>('DISCORD_CLIENT_ID');
const DISCORD_CLIENT_SECRET = configService.getOrThrow<string>(
'DISCORD_CLIENT_SECRET',
);
const SERVER_URL = configService.getOrThrow<string>('SERVER_URL');
const config = {
clientID: DISCORD_CLIENT_ID,
clientSecret: DISCORD_CLIENT_SECRET,
callbackUrl: `${SERVER_URL}/api/v1/auth/discord/callback`,
scope: [DiscordPermissionScope.Email, DiscordPermissionScope.Identify],
fetchScope: true,
prompt: 'none',
};
super(config);
}
async validate(accessToken: string, refreshToken: string, profile: any) {
DiscordStrategy.logger.debug(
`Discord Login Data ${JSON.stringify(profile)}`,
);
return { accessToken, refreshToken, profile };
}
}