Skip to content

Commit

Permalink
#8 feat: refresh 토큰 redis에 저장
Browse files Browse the repository at this point in the history
  • Loading branch information
sojungpp committed Feb 28, 2023
1 parent c625ada commit 5a5fcc3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.codepatissier.keki.user.service;

import java.time.Duration;
import java.util.Date;


Expand All @@ -13,6 +14,7 @@

import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import org.springframework.web.context.request.RequestContextHolder;
Expand All @@ -32,6 +34,8 @@ public class AuthService {
private final int accessTokenExpiryDate = 604800000;
private final int refreshTokenExpiryDate = 604800000;

private final RedisTemplate<String, String> redisTemplate;

@Value("${auth.key}")
private String key;

Expand Down Expand Up @@ -91,6 +95,7 @@ public String createRefreshToken(Long userIdx) {
.setExpiration(new Date(now.getTime() + refreshTokenExpiryDate))
.signWith(SignatureAlgorithm.HS256, key)
.compact();
redisTemplate.opsForValue().set(String.valueOf(userIdx), refreshToken, Duration.ofMillis(refreshTokenExpiryDate));
return refreshToken;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@
import org.springframework.transaction.annotation.Transactional;



import static com.codepatissier.keki.common.BaseResponseStatus.*;


@Service
@RequiredArgsConstructor
public class UserService {
private final UserRepository userRepository;
private final StoreRepository storeRepository;
private final AuthService authService;

// 로그인
Expand Down

0 comments on commit 5a5fcc3

Please sign in to comment.