generated from dannaward/create-ios-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
�[Fix] #287 - Interceptor retry 오류 수정
�[Fix] #287 - Interceptor retry 오류 수정
- Loading branch information
Showing
13 changed files
with
122 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
pophory-iOS/Global/Resources/Assets.xcassets/ErrorImg/networkFail.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file removed
BIN
-60.2 KB
pophory-iOS/Global/Resources/Assets.xcassets/ErrorImg/networkFail.imageset/Frame 514631.pdf
Binary file not shown.
24 changes: 24 additions & 0 deletions
24
...al/Resources/Assets.xcassets/ErrorImg/networkFail.imageset/img_networkError.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// | ||
// File.swift | ||
// pophory-iOS | ||
// | ||
// Created by 강윤서 on 2/19/24. | ||
// | ||
|
||
import Foundation | ||
import Alamofire | ||
|
||
final class AuthInterceptor: RequestInterceptor { | ||
|
||
static let shared = AuthInterceptor() | ||
|
||
private init() {} | ||
|
||
func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (Result<URLRequest, Error>) -> Void) { | ||
guard let urlString = Bundle.main.infoDictionary?["BASE_URL"] as? String, | ||
let url = URL(string: urlString) else { | ||
fatalError("🚨Base URL을 찾을 수 없습니다🚨") | ||
} | ||
|
||
guard urlRequest.url?.absoluteString.hasPrefix(urlString) == true, | ||
let accessToken = PophoryTokenManager.shared.fetchAccessToken(), | ||
let refreshToken = PophoryTokenManager.shared.fetchRefreshToken() else { | ||
completion(.success(urlRequest)) | ||
return | ||
} | ||
|
||
var urlRequest = urlRequest | ||
urlRequest.setValue("Bearer \(PophoryTokenManager.shared.fetchAccessToken()!)", forHTTPHeaderField: "Authorization") | ||
// urlRequest.headers.update(name: "Authorization", value: "Bearer \(PophoryTokenManager.shared.fetchAccessToken()!)") | ||
print("🍥🍥🍥adator 적용 \(urlRequest.headers)") | ||
completion(.success(urlRequest)) | ||
} | ||
|
||
func retry(_ request: Request, for session: Session, dueTo error: Error, completion: @escaping (RetryResult) -> Void) { | ||
print("🍥🍥🍥retry 진입") | ||
guard let response = request.task?.response as? HTTPURLResponse, response.statusCode == 401 else { | ||
completion(.doNotRetryWithError(error)) | ||
return | ||
} | ||
|
||
NetworkService.shared.authRepostiory.updateRefreshToken { result in | ||
switch result { | ||
case .success(let response): | ||
guard let data = response as? UpdatedAccessTokenDTO else { | ||
DispatchQueue.main.async { | ||
RootViewSwitcher.shared.setRootView(.onboarding) | ||
} | ||
completion(.doNotRetryWithError(error)) | ||
return | ||
} | ||
PophoryTokenManager.shared.saveAccessToken(data.accessToken) | ||
PophoryTokenManager.shared.saveRefreshToken(data.refreshToken) | ||
completion(.retry) | ||
default: | ||
DispatchQueue.main.async { | ||
RootViewSwitcher.shared.setRootView(.onboarding) | ||
} | ||
completion(.doNotRetryWithError(error)) | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters