-
-
Notifications
You must be signed in to change notification settings - Fork 115
/
auth.module.ts
67 lines (66 loc) · 2.26 KB
/
auth.module.ts
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { Module } from '@nestjs/common'
import { AuthService } from './service/auth.service'
import { AuthController } from './controller/auth.controller'
import { JwtModule } from '@nestjs/jwt'
import { UserModule } from '@/user/user.module'
import { GithubStrategy } from '@/config/oauth-strategy/github/github.strategy'
import { GithubOAuthStrategyFactory } from '@/config/factory/github/github-strategy.factory'
import { GoogleOAuthStrategyFactory } from '@/config/factory/google/google-strategy.factory'
import { GoogleStrategy } from '@/config/oauth-strategy/google/google.strategy'
import { GitlabOAuthStrategyFactory } from '@/config/factory/gitlab/gitlab-strategy.factory'
import { GitlabStrategy } from '@/config/oauth-strategy/gitlab/gitlab.strategy'
import { seconds, ThrottlerModule } from '@nestjs/throttler'
import { ConfigModule, ConfigService } from '@nestjs/config'
@Module({
imports: [
JwtModule.register({
global: true,
secret: process.env.JWT_SECRET ?? 'secret',
signOptions: {
expiresIn: '1d',
issuer: 'keyshade.xyz',
algorithm: 'HS256'
}
}),
UserModule,
ThrottlerModule.forRootAsync({
imports: [ConfigModule],
useFactory: (config: ConfigService) => [
{
ttl: seconds(config.get('THROTTLE_TTL')),
limit: config.get('THROTTLE_LIMIT')
}
],
inject: [ConfigService]
})
],
providers: [
AuthService,
GithubOAuthStrategyFactory,
{
provide: GithubStrategy,
useFactory: (githubOAuthStrategyFactory: GithubOAuthStrategyFactory) => {
githubOAuthStrategyFactory.createOAuthStrategy()
},
inject: [GithubOAuthStrategyFactory]
},
GoogleOAuthStrategyFactory,
{
provide: GoogleStrategy,
useFactory: (googleOAuthStrategyFactory: GoogleOAuthStrategyFactory) => {
googleOAuthStrategyFactory.createOAuthStrategy()
},
inject: [GoogleOAuthStrategyFactory]
},
GitlabOAuthStrategyFactory,
{
provide: GitlabStrategy,
useFactory: (gitlabOAuthStrategyFactory: GitlabOAuthStrategyFactory) => {
gitlabOAuthStrategyFactory.createOAuthStrategy()
},
inject: [GitlabOAuthStrategyFactory]
}
],
controllers: [AuthController]
})
export class AuthModule {}