@@ -3,13 +3,15 @@ import { OAuth2Client } from 'google-auth-library';
3
3
4
4
import { CACHE_MANAGER , Cache } from '@nestjs/cache-manager' ;
5
5
import {
6
+ BadRequestException ,
6
7
ConflictException ,
7
8
Inject ,
8
9
Injectable ,
9
10
InternalServerErrorException ,
10
11
NotFoundException ,
11
12
UnauthorizedException ,
12
13
} from '@nestjs/common' ;
14
+ import { ConfigService } from '@nestjs/config' ;
13
15
14
16
import { AuthService } from 'src/auth/auth.service' ;
15
17
import { CoolsmsService } from 'src/common/modules/coolsms/coolsms.service' ;
@@ -31,6 +33,12 @@ export class RegisterService {
31
33
private readonly coolsmsService : CoolsmsService ,
32
34
private readonly authService : AuthService ,
33
35
private readonly alertService : AlertService ,
36
+ private readonly configService : ConfigService <
37
+ {
38
+ TEST_KEY : string ;
39
+ } ,
40
+ true
41
+ > ,
34
42
@Inject ( CACHE_MANAGER ) private readonly cacheManager : Cache ,
35
43
) {
36
44
this . oAuth2Client = new OAuth2Client ( ) ;
@@ -82,7 +90,7 @@ export class RegisterService {
82
90
83
91
switch ( dto . provider ) {
84
92
case Provider . KAKAO :
85
- if ( ! dto . accessToken ) throw new UnauthorizedException ( 'Kakao accessToken is required' ) ;
93
+ if ( ! dto . accessToken ) throw new BadRequestException ( 'Kakao accessToken is required' ) ;
86
94
const kakaoUser = await this . getKakaoUser ( dto . accessToken ) ;
87
95
oauthUser = {
88
96
provider : Provider . KAKAO ,
@@ -91,7 +99,7 @@ export class RegisterService {
91
99
92
100
break ;
93
101
case Provider . GOOGLE :
94
- if ( ! dto . accessToken ) throw new UnauthorizedException ( 'Google accessToken is required' ) ;
102
+ if ( ! dto . accessToken ) throw new BadRequestException ( 'Google accessToken is required' ) ;
95
103
const googleUser = await this . getGoogleUser ( dto . accessToken ) ;
96
104
oauthUser = {
97
105
provider : Provider . GOOGLE ,
@@ -101,13 +109,23 @@ export class RegisterService {
101
109
break ;
102
110
case Provider . PHONE :
103
111
if ( ! dto . phone || ! dto . password )
104
- throw new UnauthorizedException ( 'Phone and password are required' ) ;
112
+ throw new BadRequestException ( 'Phone and password are required' ) ;
105
113
oauthUser = {
106
114
provider : Provider . PHONE ,
107
115
providerId : dto . phone ! ,
108
116
} ;
109
117
110
118
break ;
119
+ case Provider . TEST :
120
+ if ( ! dto . accessToken || ! dto . phone || ! dto . password )
121
+ throw new BadRequestException ( 'Test provider requires all fields' ) ;
122
+ if ( dto . accessToken !== this . configService . get ( 'TEST_KEY' ) )
123
+ throw new UnauthorizedException ( 'Test accessToken is incorrect' ) ;
124
+
125
+ oauthUser = {
126
+ provider : Provider . TEST ,
127
+ providerId : dto . phone ,
128
+ } ;
111
129
}
112
130
113
131
const user = await this . authService . findUserByProvider (
0 commit comments