-
Notifications
You must be signed in to change notification settings - Fork 1
[FEAT] UserDefaultsManager 구현, 앱 실행 시 토큰 갱신 로직 구현 (#268) #269
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
Conversation
UserDefaults.standard.dictionaryRepresentation 를 순환하며 삭제 시 언어가 바뀌는 등의 문제 발생 가능
액세스토큰 만료까지 30분 미만일 경우 갱신합니다.
cirtuare
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
리팩 너무 깔꼼하네용 굿굿 ~~~ 🥑💗
| // NOTE: access token 유효시간이 30분 미만이면 true | ||
| func needsTokenRefresh() -> Bool { | ||
| guard let lastRefresh = UserDefaultsManager.get(Date.self, forKey: .lastTokenRefreshDate) else { | ||
| return true | ||
| } | ||
| let elapsed = Date().timeIntervalSince(lastRefresh) | ||
| print("❄️ token elapsed: \(elapsed) / \(refreshInterval) seconds") | ||
| return elapsed >= refreshInterval | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐿️🐿️
물론 엑토와 리토 갱신 시점이 같긴 하지만,
엑토 갱신은 어처피 블랙박스라, 기존 사용자 UX에서 불편감을 주는 건 리토가 만료되었을 때인데
굳이 엑토가 30분 남은 시점에서 (= 2시간 반 전 리토를 갱신함)까지 갱신해야 할 필요가 있나 싶습니다!
어처피 리토 갱신이 목적이면, 그냥 엑토가 만료되었을 때만 호출해도 되지 않을까요?
-> 엑토 30분 이하 남음, 리토는 당연히 기간 남아있음 = 사용 도중 엑토 만료되면 블랙박스로 갱신, 엑토 만료 전 앱을 나가도 어처피 리토는 2시간 반 ~ 3시간 전에 갱신되어서 만료기간 3달인 리토 갱신에는 별 의미 없음
-> 엑토가 만료됨, 리토는 기간 남아있음 = 리토 갱신되게 하기
-> 엑토 & 리토 모두 만료됨 = 로그인해야 하는 경우
저는 이렇게 이해했습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 액토가 30분 이하 남았을 때 블랙박스에 의존하지 않고 미리 갱신하려는 목적으로 이렇게 구현했습니다. 이렇게 하면 사용자가 앱을 잠깐 사용하더라도 리토를 항상 최신 상태로 유지할 수 있어서요.
그런데 말씀 주신 방향도 타당하게 느껴지네요!
말씀대로, 액토가 만료되었을 때, 즉 앱 진입 후 토큰 갱신이 확정인 상황만 토큰 갱신되도록 하겠습니다:D
- 액토 유효할 때 => 앱 진입
- 액토가 만료되었을 때 => 토큰 갱신 후 앱 진입
- 액토 & 리토 모두 만료 => 로그인
액토 유효할 때 => 앱 진입 액토가 만료되었을 때 => 토큰 갱신 후 앱 진입 액토 & 리토 모두 만료 => 로그인
🐿️ Pull Requests
🪵 작업 브랜치
🥔 작업 내용
1. UserDefaultsManager 구현
구현 배경
로그아웃/탈퇴 등의 상황에서
UserDefaults.standard.dictionaryRepresentation를 순환하며 항목을 삭제하고 있었습니다.그러나, 이는 시스템 정보도 삭제하기 때문에 로그아웃/탈퇴 후 언어가 바뀌는 등의 문제가 발생할 수 있습니다.
결과
UserDefaultsManager를 만들었습니다.
👉 앱의 keys만 안전하게 삭제 가능
👉 UserDefaults를 더 편하게 set, get, remove 가능
2. Splash에서 토큰 갱신
구현 배경
Refresh token이 만료되었을 경우)
-기존 로직: 앱 진입 -> API 호출 -> token error -> token refresh 실패 -> 로그인 화면으로 이동
-문제: 앱 진입 후 갑자기 로그인 화면으로 튕기는 UX적 불편감
구현 상세
Splash에서 미리 토큰 상태를 점검 및 갱신하여, 사용자 경험을 자연스럽게 유지했습니다.
(= 토큰 생성 후 2시간 30분(9000초) 지났을 때 refresh)
결과
<Access token 남은 시간 30분 이상>: 바로 앱 진입 (자동로그인)
<Access token 남은 시간 30분 미만 or 만료>: Refresh Token -> 앱 진입 (자동로그인)
<Refresh Token 만료>: 로그인 -> 앱 진입
📸 스크린샷
(토큰 갱신 주기 임의로 조정하여 테스트 완료)
(임의로 토큰 삭제하여 테스트 완료)
💥 To be sure
🌰 Resolve issue