Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify Auth Logic #111

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
@Setter
public class AuthConfig {
private String defaultNickname;
private String defaultPassword;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.swmaestro.repl.gifthub.auth.dto.JwtTokenDto;
import org.swmaestro.repl.gifthub.auth.dto.OAuthTokenDto;
import org.swmaestro.repl.gifthub.auth.dto.SignInDto;
import org.swmaestro.repl.gifthub.auth.dto.SignOutDto;
import org.swmaestro.repl.gifthub.auth.dto.SignUpDto;
import org.swmaestro.repl.gifthub.auth.service.AuthService;
import org.swmaestro.repl.gifthub.auth.service.RefreshTokenService;
Expand Down Expand Up @@ -162,13 +161,12 @@ public ResponseEntity<Message> appleSignIn(HttpServletRequest request, @RequestB
@ApiResponse(responseCode = "200", description = "로그인 성공"),
@ApiResponse(responseCode = "400(401)", description = "존재하지 않는 사용자")
})
public ResponseEntity<Message> signOut(HttpServletRequest request, @RequestBody SignOutDto signOutDto) {
public ResponseEntity<Message> signOut(HttpServletRequest request) {
String username = jwtProvider.getUsername(jwtProvider.resolveToken(request).substring(7));
authService.signOut(username, signOutDto);
authService.signOut(username);
return ResponseEntity.ok(
SuccessMessage.builder()
.path(request.getRequestURI())
.data(null)
.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.swmaestro.repl.gifthub.auth.dto.OAuthTokenDto;
import org.swmaestro.repl.gifthub.auth.dto.OAuthUserInfoDto;
import org.swmaestro.repl.gifthub.auth.dto.SignInDto;
import org.swmaestro.repl.gifthub.auth.dto.SignOutDto;
import org.swmaestro.repl.gifthub.auth.dto.SignUpDto;
import org.swmaestro.repl.gifthub.auth.entity.Member;
import org.swmaestro.repl.gifthub.auth.entity.OAuth;
Expand Down Expand Up @@ -91,6 +90,7 @@ public JwtTokenDto signIn(OAuthTokenDto oAuthTokenDto, OAuthPlatform platform) {
Member newMember = Member.builder()
.username(memberService.generateOAuthUsername())
.nickname(authConfig.getDefaultNickname())
.password(passwordEncoder.encode(authConfig.getDefaultPassword()))
.build();
// 회원 정보 저장
Member member = memberService.create(newMember);
Expand All @@ -115,21 +115,22 @@ private JwtTokenDto generateJwtTokenDto(Member member) {
.refreshToken(refreshToken)
.build();

refreshTokenService.storeRefreshToken(jwtTokenDto, member.getUsername());

return jwtTokenDto;
}

/**
* 로그아웃
* @param username
* @param signOutDto
*/
@Transactional
public void signOut(String username, SignOutDto signOutDto) {
public void signOut(String username) {
Member member = memberRepository.findByUsername(username);
System.out.println("member = " + member.getUsername());
if (member == null) {
throw new BusinessException("존재하지 않는 사용자입니다.", StatusEnum.UNAUTHORIZED);
}
refreshTokenService.deleteRefreshToken(username);
deviceTokenService.delete(signOutDto.getDeviceToken());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,6 @@ public boolean isExists(OAuthUserInfoDto oAuthUserInfoDto) {

private String getStringOrNull(JsonElement element, String fieldName) {
JsonElement fieldElement = element.getAsJsonObject().get(fieldName);
return !fieldElement.isJsonNull() ? fieldElement.getAsString() : null;
return fieldElement != null ? fieldElement.getAsString() : null;
}
}