Skip to content

Commit

Permalink
Merge pull request #112 from dev-hooon/feat/#106
Browse files Browse the repository at this point in the history
feat : Member login & logout 기능 구현
  • Loading branch information
kkangh00n authored Jan 17, 2024
2 parents de44359 + 7cd8d32 commit c2d194a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.prgrms.catchtable.member.controller;

import com.prgrms.catchtable.common.login.LogIn;
import com.prgrms.catchtable.member.domain.Member;
import com.prgrms.catchtable.member.service.MemberService;
import java.net.URI;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/members")
public class MemberController {

private final MemberService memberService;

@GetMapping("/login/kakao")
public ResponseEntity<?> loginRedirect(){
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setLocation(URI.create("/oauth2/authorization/kakao"));
return new ResponseEntity<>(httpHeaders, HttpStatus.MOVED_PERMANENTLY);
}

@PostMapping("/logout")
public ResponseEntity<String> logout(@LogIn Member member){
memberService.logout(member.getEmail());
return ResponseEntity.ok("logout");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public Token oauthLogin(OAuthAttribute attributes) {
return createTotalToken(email);
}

@Transactional
public void logout(String email){
refreshTokenService.deleteRefreshToken(email);
}

private Token createTotalToken(String email) {
Token totalToken = jwtTokenProvider.createToken(email, Role.MEMBER);
refreshTokenService.saveRefreshToken(totalToken);
Expand Down

0 comments on commit c2d194a

Please sign in to comment.