File tree 2 files changed +18
-3
lines changed
src/main/java/com/ivory/ivory
2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -23,8 +23,8 @@ public class AuthController {
23
23
24
24
@ PostMapping ("/sign-up" )
25
25
public CustomApiResponse <?> signup (@ Valid @ RequestBody SignUpDto signUpDto ) {
26
- authService .signup (signUpDto );
27
- return CustomApiResponse .createSuccess (HttpStatus .CREATED .value (),"회원가입을 성공하였습니다." ,null );
26
+ TokenDto dto = authService .signup (signUpDto );
27
+ return CustomApiResponse .createSuccess (HttpStatus .CREATED .value (),"회원가입을 성공하였습니다." , dto );
28
28
}
29
29
30
30
@ PostMapping ("/login" )
Original file line number Diff line number Diff line change @@ -29,14 +29,29 @@ public class AuthService {
29
29
private final RefreshTokenRepository refreshTokenRepository ;
30
30
31
31
@ Transactional
32
- public void signup (SignUpDto signUpDto ) {
32
+ public TokenDto signup (SignUpDto signUpDto ) {
33
33
if (memberRepository .existsByEmail (signUpDto .getEmail ())) {
34
34
throw new ResponseStatusException (HttpStatus .BAD_REQUEST , "이미 가입되어 있는 유저입니다." );
35
35
}
36
36
37
37
Member member = signUpDto .toMember (passwordEncoder );
38
38
39
39
memberRepository .save (member );
40
+
41
+ UsernamePasswordAuthenticationToken authenticationToken =
42
+ new UsernamePasswordAuthenticationToken (signUpDto .getEmail (), signUpDto .getPassword ());
43
+
44
+ Authentication authentication = authenticationManagerBuilder .getObject ().authenticate (authenticationToken );
45
+
46
+ TokenDto tokenDto = tokenProvider .generateTokenDto (authentication );
47
+
48
+ RefreshToken refreshToken = RefreshToken .builder ()
49
+ .key (authentication .getName ())
50
+ .value (tokenDto .getRefreshToken ())
51
+ .build ();
52
+ refreshTokenRepository .save (refreshToken );
53
+
54
+ return tokenDto ;
40
55
}
41
56
42
57
@ Transactional
You can’t perform that action at this time.
0 commit comments