Skip to content

Commit d8d42d0

Browse files
committed
feat: add case register test user
1 parent b85a230 commit d8d42d0

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/modules/register/register.service.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import { OAuth2Client } from 'google-auth-library';
33

44
import { CACHE_MANAGER, Cache } from '@nestjs/cache-manager';
55
import {
6+
BadRequestException,
67
ConflictException,
78
Inject,
89
Injectable,
910
InternalServerErrorException,
1011
NotFoundException,
1112
UnauthorizedException,
1213
} from '@nestjs/common';
14+
import { ConfigService } from '@nestjs/config';
1315

1416
import { AuthService } from 'src/auth/auth.service';
1517
import { CoolsmsService } from 'src/common/modules/coolsms/coolsms.service';
@@ -31,6 +33,12 @@ export class RegisterService {
3133
private readonly coolsmsService: CoolsmsService,
3234
private readonly authService: AuthService,
3335
private readonly alertService: AlertService,
36+
private readonly configService: ConfigService<
37+
{
38+
TEST_KEY: string;
39+
},
40+
true
41+
>,
3442
@Inject(CACHE_MANAGER) private readonly cacheManager: Cache,
3543
) {
3644
this.oAuth2Client = new OAuth2Client();
@@ -82,7 +90,7 @@ export class RegisterService {
8290

8391
switch (dto.provider) {
8492
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');
8694
const kakaoUser = await this.getKakaoUser(dto.accessToken);
8795
oauthUser = {
8896
provider: Provider.KAKAO,
@@ -91,7 +99,7 @@ export class RegisterService {
9199

92100
break;
93101
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');
95103
const googleUser = await this.getGoogleUser(dto.accessToken);
96104
oauthUser = {
97105
provider: Provider.GOOGLE,
@@ -101,13 +109,23 @@ export class RegisterService {
101109
break;
102110
case Provider.PHONE:
103111
if (!dto.phone || !dto.password)
104-
throw new UnauthorizedException('Phone and password are required');
112+
throw new BadRequestException('Phone and password are required');
105113
oauthUser = {
106114
provider: Provider.PHONE,
107115
providerId: dto.phone!,
108116
};
109117

110118
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+
};
111129
}
112130

113131
const user = await this.authService.findUserByProvider(

0 commit comments

Comments
 (0)