토큰 만료를 처리하기 위해 확장함수 추가
This commit is contained in:
parent
e98847179a
commit
0e0d7a3c24
|
@ -0,0 +1,33 @@
|
|||
//
|
||||
// MoyaProviderExtension.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/11/17.
|
||||
//
|
||||
|
||||
import Moya
|
||||
import Foundation
|
||||
|
||||
extension MoyaProvider {
|
||||
convenience init() {
|
||||
self.init(plugins: [AuthPlugin()])
|
||||
}
|
||||
}
|
||||
|
||||
final class AuthPlugin: PluginType {
|
||||
func didReceive(_ result: Result<Response, MoyaError>, target: TargetType) {
|
||||
switch result {
|
||||
case .success(let response):
|
||||
DEBUG_LOG("\(response.statusCode) \(response)")
|
||||
if response.statusCode == 401 {
|
||||
AppState.shared.setAppStep(step: .main)
|
||||
UserDefaults.reset()
|
||||
}
|
||||
break
|
||||
|
||||
case .failure(_):
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue