//
//  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
        }
    }
}

