-
Notifications
You must be signed in to change notification settings - Fork 1
[#302] AuthService 도입 및 SceneDelegate 책임 분리 코드 리팩토링 #303
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
base: develop
Are you sure you want to change the base?
Changes from all commits
45d72fc
07aba0d
1d1a9bb
640cbcd
22216b9
c8d0c86
ef6bbc9
7bf71e2
53d9c0c
486bd64
bc2b4fe
c0462a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,6 @@ final class LoginViewController: BaseViewController { | |
| // MARK: - Properties | ||
|
|
||
| public static let isVacationPeriod = false | ||
| public var toastMessage: String? | ||
| private let authProvider = MoyaProvider<AuthRouter>(session: Session(interceptor: AuthInterceptor.shared)) | ||
| private let myProvider = MoyaProvider<MyRouter>(session: Session(interceptor: AuthInterceptor.shared)) | ||
|
|
||
|
|
@@ -28,10 +27,11 @@ final class LoginViewController: BaseViewController { | |
|
|
||
| // MARK: - Life Cycle | ||
|
|
||
| override func viewWillAppear(_ animated: Bool) { | ||
| super.viewWillAppear(animated) | ||
| handleAutoLogin() | ||
| } | ||
| // override func viewWillAppear(_ animated: Bool) { | ||
| // super.viewWillAppear(animated) | ||
| // showToastMessageIfNeeded() | ||
| //// handleAutoLogin() | ||
| // } | ||
|
|
||
| override func viewDidLoad() { | ||
| super.viewDidLoad() | ||
|
|
@@ -80,16 +80,7 @@ final class LoginViewController: BaseViewController { | |
| Analytics.logEvent("LoginViewControllerLoad", parameters: nil) | ||
| #endif | ||
| } | ||
|
|
||
| /// Realm에 저장된 토큰이 있는지 확인 후, 있으면 홈 화면으로 이동한다. | ||
| private func handleAutoLogin() { | ||
| guard hasStoredToken() else { return } | ||
| #if DEBUG | ||
| print("저장된 AccessToken: ", RealmService.shared.getToken()) | ||
| #endif | ||
| changeIntoHomeViewController() | ||
| } | ||
|
|
||
|
|
||
| private func hasStoredToken() -> Bool { | ||
| !RealmService.shared.getToken().isEmpty | ||
| } | ||
|
|
@@ -108,30 +99,33 @@ final class LoginViewController: BaseViewController { | |
| /// 닉네임 설정이 필요한지 확인 후, 필요하면 닉네임 설정 화면으로, 아니면 홈 화면으로 이동한다. | ||
| private func handleNicknameCheck(info: MyInfoResponse) { | ||
| if let nickname = info.nickname { | ||
| // 사용자의 닉네임을 업데이트하고 홈 화면으로 이동 | ||
| if let currentUserInfo = UserInfoManager.shared.getCurrentUserInfo() { | ||
| UserInfoManager.shared.updateNickname(for: currentUserInfo, nickname: nickname) | ||
| print("[디버깅] 닉네임 존재함: \(nickname)") | ||
|
|
||
| let currentUser = UserInfoManager.shared.getCurrentUserInfo() | ||
| print("[디버깅] currentUserInfo: \(String(describing: currentUser))") | ||
|
|
||
| if let u = currentUser { | ||
| UserInfoManager.shared.updateNickname(for: u, nickname: nickname) | ||
| print("[디버깅] 닉네임 업데이트 완료") | ||
| } else { | ||
| print("[디버깅] currentUserInfo가 nil임") | ||
| } | ||
| changeIntoHomeViewController() | ||
| } else { | ||
| // 닉네임 설정이 필요한 경우 | ||
| print("[디버깅] 닉네임이 없음 → 닉네임 설정 화면으로 이동") | ||
| let setNicknameVC = SetNickNameViewController() | ||
| navigationController?.pushViewController(setNicknameVC, animated: true) | ||
| } | ||
|
Comment on lines
101
to
117
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 디버깅 목적으로 추가된 if let nickname = info.nickname {
if let currentUser = UserInfoManager.shared.getCurrentUserInfo() {
UserInfoManager.shared.updateNickname(for: currentUser, nickname: nickname)
}
} else {
let setNicknameVC = SetNickNameViewController()
navigationController?.pushViewController(setNicknameVC, animated: true)
}
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 로그 보면서 작업해서 print 문들은 아직 다 그대로 냅뒀습니다! |
||
| } | ||
|
|
||
|
|
||
| /// 토큰을 Realm에 저장하고, 디버깅 로그를 출력한다. | ||
| private func storeTokensAndPrintDebugLogs(accessToken: String, refreshToken: String) { | ||
| RealmService.shared.addToken(accessToken: accessToken, refreshToken: refreshToken) | ||
| #if DEBUG | ||
| print("⭐️⭐️ 토큰 저장 성공 ⭐️⭐️") | ||
| #endif | ||
| } | ||
|
|
||
| private func showToastMessageIfNeeded() { | ||
| guard let toastMessage = self.toastMessage else { return } | ||
| view.showToast(message: toastMessage) | ||
| } | ||
|
|
||
|
|
||
| // MARK: - 액션 메서드 | ||
|
|
||
|
|
@@ -192,14 +186,15 @@ extension LoginViewController { | |
| let accessToken = data.accessToken | ||
| let refreshToken = data.refreshToken | ||
|
|
||
| // 토큰을 로컬에 저장 | ||
| // 1) 토큰 저장 | ||
| storeTokensAndPrintDebugLogs(accessToken: accessToken, refreshToken: refreshToken) | ||
|
|
||
| // 로컬 매니저에 유저 정보 생성 | ||
| // 2) 인증 상태 업데이트 (SceneDelegate.observeAuthState가 화면 전환 처리) | ||
| AuthService.shared.login(accessToken: accessToken, refreshToken: refreshToken) // | ||
|
|
||
| // 3) 로컬 매니저에 유저 정보 생성 | ||
| _ = UserInfoManager.shared.createUserInfo(accountType: accountType) | ||
|
|
||
| // 닉네임 등 정보를 확인하기 위해 프로필 조회 | ||
| getMyInfo() | ||
| } catch { | ||
| switch accountType { | ||
| case .apple: | ||
|
|
@@ -255,27 +250,6 @@ extension LoginViewController { | |
| } | ||
| } | ||
| } | ||
|
|
||
| /// 서버에서 현재 유저 정보를 조회 | ||
| private func getMyInfo() { | ||
| myProvider.request(.myInfo) { [weak self] result in | ||
| guard let self else { return } | ||
| switch result { | ||
| case let .success(moyaResponse): | ||
| do { | ||
| let responseData = try moyaResponse.map(BaseResponse<MyInfoResponse>.self) | ||
| guard let responseData = responseData.result else { | ||
| return | ||
| } | ||
| handleNicknameCheck(info: responseData) | ||
| } catch { | ||
| print(error.localizedDescription) | ||
| } | ||
| case let .failure(error): | ||
| print(error.localizedDescription) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // MARK: - 카카오 사용자 정보 가져오기 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,7 +101,7 @@ final class HomeViewController: BaseViewController { | |
|
|
||
| @objc | ||
| private func didTapRightBarButton() { | ||
| if RealmService.shared.isAccessTokenPresent() { | ||
| if AuthService.shared.isTokenValid() { | ||
| navigateToMyPage() | ||
| } else { | ||
| presentLoginAlert() | ||
|
|
@@ -114,16 +114,19 @@ final class HomeViewController: BaseViewController { | |
| } | ||
|
|
||
| private func presentLoginAlert() { | ||
| let alert = UIAlertController(title: "로그인이 필요한 서비스입니다", | ||
| message: "로그인 하시겠습니까?", | ||
| preferredStyle: .alert) | ||
| let confirmAction = UIAlertAction(title: "확인", style: .default) { [weak self] _ in | ||
| self?.navigateToLogin() | ||
| let alert = UIAlertController( | ||
| title: "로그인이 필요한 서비스입니다", | ||
| message: "로그인 하시겠습니까?", | ||
| preferredStyle: .alert | ||
| ) | ||
| let confirm = UIAlertAction(title: "확인", style: .default) { _ in | ||
| AuthService.shared.logout(message: nil) | ||
| self.navigateToLogin() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이건 수정해야합니다. |
||
| } | ||
| let cancelAction = UIAlertAction(title: "취소", style: .cancel, handler: nil) | ||
| alert.addAction(confirmAction) | ||
| alert.addAction(cancelAction) | ||
| present(alert, animated: true, completion: nil) | ||
| let cancel = UIAlertAction(title: "취소", style: .cancel) | ||
| alert.addAction(confirm) | ||
| alert.addAction(cancel) | ||
| present(alert, animated: true) | ||
| } | ||
|
|
||
| private func navigateToLogin() { | ||
|
|
||
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.
TokenManager클래스가final키워드 없이 선언되었습니다. 만약 상속을 의도한 것이 아니라면,final키워드를 추가하여 클래스가 상src되지 않음을 명시하고 잠재적인 오용을 방지하는 것이 좋습니다. 이는 성능 최적화에도 도움이 될 수 있습니다.