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

[Feat] #193 - 액세스 토큰 만료 로직 구현 #207

Merged
merged 7 commits into from
Jan 7, 2024
Merged

Conversation

jeongdung-eo
Copy link
Member

@jeongdung-eo jeongdung-eo commented Nov 23, 2023

🫧 작업한 내용

  • 액세시 토큰 만료 로직 구현

🔫 PR Point

  • 응답이 내려온 시점에 특정 작업을 수행하기 위해서 Moya Plugin을 활용
  • interceptor를 활용해서 401 액세스 토큰 에러 분기처리
  • status code가 2xx가 아닌 경우 로그인 뷰로 화면 전환

📸 스크린샷

Simulator.Screen.Recording.-.iPhone.SE.3rd.generation.-.2023-11-23.at.20.35.58.mp4

📮 관련 이슈

Comment on lines 60 to 67
switch statusCode {
case 200..<300:
return
default:

let sceneDelegate = UIApplication.shared.connectedScenes.first?.delegate as! SceneDelegate
sceneDelegate.window?.rootViewController = UINavigationController(rootViewController: AuthViewController())
}
Copy link
Member

@hyesuuou hyesuuou Nov 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요렇게 해줘도 동작은 하지만 사실 요 플러그인의 기능은 로깅이니까
로깅하는 역할에서 화면 전환을 알 필요가 있나? 에 대해서는 한번 더 생각해보면 좋을 것 같습니다~
클래스의 역할만 보면 UIKit이 필요하지 않을 것 같은데 이 화면전환으로 인해서 import 해야하니까 요런 부분도 역할 분리가 잘 된게 맞는지 의심해볼 포인트 같아요!

저희 플젝에서는 Moya를 쓰니까 Moya를 기준으로 알아보면 좋을거를 좀 소개를 해보자면
Moya가 Alamofire를 감싼 형태인데, Alamofire에서 Intercepter라고 해서
요청을 보내기 전이나 후에 필요한 처리를 할 수 있는 API를 제공하고 있어요!

요걸쓰면 응답이 내려온 시점에 특정 작업을 수행하기 위해서 이 부분도 해결되지 않을까 싶네여!

이거를 Moya에서도 provider를 생성할때 LogginPlugin을 넣어준것 처럼

provider = MoyaProvider<~~Router>(
        session: Session(interceptor: 만들어준인터셉터()),
        plugins: [MoyaLoggingPlugin()]
    )

이렇게 만들어주면 해당 provider를 사용하는 곳에선 모두 저 인터셉트를 거치게 됩미다~

https://ios-development.tistory.com/730

요 블로그 보면 좋을 것같아요!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넹 ! interceptor 활용해서 수정할게요 :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -56,6 +56,15 @@ final class MoyaLoggingPlugin: PluginType {
}
log.append("------------------- END HTTP (\(response.data.count)-byte body) -------------------")
print(log)

switch statusCode {
case 200..<300:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 글구 케이스를 이렇게 나누면 400에러나 500에러가 뜰때도 보내버려서 분기처리 조건을 수정해야 할듯 합니다~!
아마 서버에서 401을 줄텐데 401인 경우만 이렇게 해야할 것 같아요~

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아아!! 401만 분기처리해서 올릴게요:)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -5,7 +5,7 @@
// Created by 김민서 on 2023/02/23.
//

import Foundation
import UIKit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UIKit도 이제 없어두 될거 같아여!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넹!
db4086c

@jeongdung-eo jeongdung-eo merged commit 7125482 into develop Jan 7, 2024
1 check passed
@jeongdung-eo jeongdung-eo deleted the feat/#193 branch January 7, 2024 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feat] 액세스 토큰 만료 로직 처리
2 participants