Skip to content

Commit

Permalink
๐Ÿš‘ ๊ธด๊ธ‰ ์ˆ˜์ • - ๋กœ๊ทธ์ธ ์‹œ token ๋ฐ์ดํ„ฐ๊ฐ€ ๊ฐฑ์‹ ๋˜์ง€ ์•Š๋Š” ์˜ค๋ฅ˜ ์ˆ˜์ •
Browse files Browse the repository at this point in the history
๐Ÿš‘ ๊ธด๊ธ‰ ์ˆ˜์ • - ๋กœ๊ทธ์ธ ์‹œ token ๋ฐ์ดํ„ฐ๊ฐ€ ๊ฐฑ์‹ ๋˜์ง€ ์•Š๋Š” ์˜ค๋ฅ˜ ์ˆ˜์ •
  • Loading branch information
parkswon1 authored Aug 8, 2024
2 parents 4b1a3cb + e14e978 commit 69b7469
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
12 changes: 4 additions & 8 deletions src/main/java/darkoverload/itzip/feature/jwt/domain/Token.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,10 @@ public class Token {
private String grantType;

// ์—…๋ฐ์ดํŠธ ๋นŒ๋”
public Token update(String accessToken, String refreshToken, String grantType) {
return Token.builder()
.id(this.id)
.user(this.user)
.accessToken(accessToken)
.refreshToken(refreshToken)
.grantType(grantType)
.build();
public void update(String accessToken, String refreshToken, String grantType) {
this.accessToken = accessToken;
this.refreshToken = refreshToken;
this.grantType = grantType;
}

public TokenEntity convertToEntity() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.Optional;

public interface TokenRepository extends JpaRepository<TokenEntity, Long> {
TokenEntity findByUserEntityId(Long userId);
Optional<TokenEntity> findByUserEntityId(Long userId);
Optional<TokenEntity> findByAccessToken(String accessToken);
Optional<TokenEntity> findByRefreshToken(String refreshToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public class TokenServiceImpl implements TokenService {
*/
@Transactional
public void saveOrUpdate(Token token) {
Token oldToken = tokenRepository.findByUserEntityId(token.getUser().getId()).convertToDomain();
Optional<Token> oldToken = tokenRepository.findByUserEntityId(token.getUser().getId()).map(TokenEntity::convertToDomain);

if (oldToken == null) {
if (oldToken.isEmpty()) {
tokenRepository.save(token.convertToEntity());
} else {
oldToken.update(token.getAccessToken(), token.getRefreshToken(), token.getGrantType());
oldToken.get().update(token.getAccessToken(), token.getRefreshToken(), token.getGrantType());

tokenRepository.save(oldToken.convertToEntity());
tokenRepository.save(oldToken.get().convertToEntity());
}
}

Expand Down

0 comments on commit 69b7469

Please sign in to comment.