Skip to content

Commit 37bef52

Browse files
committed
Refactor: 코드 리뷰 반영
- NetworkService에서 endpoint.isAuthorized 값 확인하여 헤더에 토큰 값 세팅해주는 로직으로 수정 - 카카오 유저 정보 (닉네임, 프로필 이미지 URL) 메인스레드에서 동작하는 것 제거 - SceneDelegate에서 SplashView를 먼저 표시하고, reissueToken 결과에 따라 rootViewController 교체하도록 구조 개선
1 parent 4a56753 commit 37bef52

13 files changed

Lines changed: 96 additions & 26 deletions

File tree

Projects/App/Sources/SceneDelegate.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
2323
guard let userDataRepository = DIContainer.shared.resolve(type: UserDataRepositoryProtocol.self)
2424
else { fatalError("userDataRepository 의존성이 등록되지 않았습니다.") }
2525

26-
Task {
26+
window.rootViewController = SplashView()
27+
window.makeKeyAndVisible()
28+
self.window = window
29+
30+
Task { @MainActor in
2731
let isLogined = await userDataRepository.reissueToken()
2832
if isLogined {
2933
window.rootViewController = TabBarView()
@@ -32,8 +36,6 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
3236
let navigationController = UINavigationController(rootViewController: introView)
3337
window.rootViewController = navigationController
3438
}
35-
window.makeKeyAndVisible()
36-
self.window = window
3739
}
3840
}
3941

Projects/DataSource/Sources/Common/Error/AuthError.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
enum AuthError: Error, CustomStringConvertible {
99
case kakaoTokenFetchFailed
10+
case kakaoUserInformationFetchFailed
1011
case tokenSaveFailed
1112
case tokenLoadFailed
1213
case tokenRemoveFailed
@@ -20,6 +21,8 @@ enum AuthError: Error, CustomStringConvertible {
2021
switch self {
2122
case .kakaoTokenFetchFailed:
2223
return "카카오 토큰을 가져오는데 실패했습니다."
24+
case .kakaoUserInformationFetchFailed:
25+
return "카카오 유저 정보를 가져오는데 실패했습니다."
2326
case .tokenSaveFailed:
2427
return "토큰 저장에 실패했습니다."
2528
case .tokenLoadFailed:

Projects/DataSource/Sources/Endpoint/AuthEndpoint.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ extension AuthEndpoint: Endpoint {
4141
"accept": "*/*"
4242
]
4343

44-
if isAuthorized {
45-
let accessToken = try! TokenManager.shared.loadToken(tokenType: .accessToken)
46-
headers["Authorization"] = "Bearer \(accessToken)"
47-
}
48-
4944
switch self {
5045
case .login(_, _, let token):
5146
headers["SocialAccessToken"] = token

Projects/DataSource/Sources/Endpoint/OnboardingEndpoint.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,10 @@ extension OnboardingEndpoint: Endpoint {
2929
}
3030

3131
var headers: [String : String] {
32-
var headers: [String: String] = [
32+
let headers: [String: String] = [
3333
"Content-Type": "application/json",
3434
"accept": "*/*"
3535
]
36-
37-
if isAuthorized {
38-
let accessToken = try! TokenManager.shared.loadToken(tokenType: .accessToken)
39-
headers["Authorization"] = "Bearer \(accessToken)"
40-
}
41-
4236
return headers
4337
}
4438

Projects/DataSource/Sources/NetworkService/NetworkService.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ final class NetworkService {
1515
private init() { }
1616

1717
func request<T: Decodable>(endpoint: Endpoint, type: T.Type) async throws -> T? {
18-
let request = try endpoint.makeURLRequest()
18+
var request = try endpoint.makeURLRequest()
19+
if endpoint.isAuthorized {
20+
let accessToken = try TokenManager.shared.loadToken(tokenType: .accessToken)
21+
request.headers["Authorization"] = "Bearer \(accessToken)"
22+
}
1923
let (data, response) = try await URLSession.shared.data(for: request)
2024

2125
guard let httpResponse = response as? HTTPURLResponse

Projects/DataSource/Sources/Repository/AuthRepository.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,11 @@ final class AuthRepository: AuthRepositoryProtocol {
104104
let profileImageUrl = user?.kakaoAccount?.profile?.profileImageUrl {
105105
continuation.resume(returning: (nickname, profileImageUrl))
106106
} else {
107-
continuation.resume(throwing: AuthError.kakaoTokenFetchFailed)
107+
continuation.resume(throwing: AuthError.kakaoUserInformationFetchFailed)
108108
}
109109
}
110110

111-
Task { @MainActor in
112-
UserApi.shared.me(completion: resultHandler)
113-
}
111+
UserApi.shared.me(completion: resultHandler)
114112
}
115113
}
116114

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "IntroGraphic.png",
5+
"idiom" : "universal",
6+
"scale" : "1x"
7+
},
8+
{
9+
"filename" : "IntroGraphic@2x.png",
10+
"idiom" : "universal",
11+
"scale" : "2x"
12+
},
13+
{
14+
"filename" : "IntroGraphic@3x.png",
15+
"idiom" : "universal",
16+
"scale" : "3x"
17+
}
18+
],
19+
"info" : {
20+
"author" : "xcode",
21+
"version" : 1
22+
}
23+
}
30.1 KB
Loading
81.3 KB
Loading
156 KB
Loading

0 commit comments

Comments
 (0)