@@ -9,53 +9,42 @@ import { HttpInternalServerErrorException } from "@src/http-exceptions/exception
9
9
import { COMMON_ERROR_CODE } from "@src/constants/error/common/common-error-code.constant" ;
10
10
import { AUTH_ERROR_CODE } from "@src/constants/error/auth/auth-error-code.constant" ;
11
11
import { AuthService } from "../../services/auth.service" ;
12
+ import { AuthRegistrationService } from "./auth-registration.service" ;
12
13
13
14
@Injectable ( )
14
15
export class AuthSocialService {
15
16
constructor (
16
17
private readonly usersService : UsersService ,
17
18
private readonly authService : AuthService ,
19
+ private readonly authRegistrationService : AuthRegistrationService ,
18
20
) { }
19
21
20
22
async signUp ( signUpRequestBodyDto : SignUpRequestBodyDto ) {
21
23
const {
22
24
loginType,
23
25
snsToken,
24
- email,
25
- phoneNumber,
26
26
} = signUpRequestBodyDto ;
27
-
27
+
28
+ // 동시성 문제
29
+ const isUserRegistered = this . authRegistrationService . isUserRegistered ( { loginType, snsToken } )
30
+ if ( ! isUserRegistered ) {
31
+ throw new HttpBadRequestException ( {
32
+ code : AUTH_ERROR_CODE . ACCOUNT_NOT_FOUND ,
33
+ } ) ;
34
+ }
35
+
28
36
const snsProfile = await getSnsProfile ( loginType , snsToken ) ;
29
- if ( ! snsProfile . sns_id ) {
37
+ if ( ! snsProfile . snsId ) {
30
38
throw new HttpInternalServerErrorException ( {
31
39
code : COMMON_ERROR_CODE . SERVER_ERROR ,
32
40
ctx : '소셜 프로필 조회 중 알 수 없는 에러' ,
33
41
} ) ;
34
42
}
35
43
36
- const existUser = await this . usersService . findOneBy ( {
37
- loginType,
38
- email : email ,
39
- phoneNumber : phoneNumber ,
40
- } ) ;
41
-
42
- if ( existUser ) {
43
- if ( existUser . email . toLowerCase ( ) === email . toLowerCase ( ) ) {
44
- throw new HttpConflictException ( {
45
- code : USER_ERROR_CODE . ALREADY_EXIST_USER_EMAIL ,
46
- } ) ;
47
- }
48
- if ( existUser . phoneNumber === phoneNumber ) {
49
- throw new HttpConflictException ( {
50
- code : USER_ERROR_CODE . ALREADY_EXIST_USER_PHONE_NUMBER ,
51
- } ) ;
52
- }
53
- }
54
-
55
- const user = this . usersService . create ( {
56
- ...signUpRequestBodyDto ,
57
- snsId : snsProfile . sns_id ,
58
- password : null
44
+ const user = await this . usersService . create ( {
45
+ ...signUpRequestBodyDto ,
46
+ snsId : snsProfile . snsId ,
47
+ password : null
59
48
} )
60
49
61
50
return user ;
@@ -66,7 +55,7 @@ export class AuthSocialService {
66
55
67
56
const snsProfile = await getSnsProfile ( loginType , snsToken ) ;
68
57
69
- if ( ! snsProfile . sns_id ) {
58
+ if ( ! snsProfile . snsId ) {
70
59
throw new HttpInternalServerErrorException ( {
71
60
code : COMMON_ERROR_CODE . SERVER_ERROR ,
72
61
ctx : '소셜 프로필 조회 중 알 수 없는 에러' ,
@@ -75,7 +64,7 @@ export class AuthSocialService {
75
64
76
65
const existUser = await this . usersService . findOneBy ( {
77
66
loginType,
78
- snsId : snsProfile . sns_id
67
+ snsId : snsProfile . snsId
79
68
} ) ;
80
69
81
70
if ( ! existUser ) {
0 commit comments