I save my login token with UserDefault. Here is the code :
AF.request(encodeURL, method: .post, parameters: nil, headers: headers, interceptor: nil)
.responseString { response in
switch response.result{
case .success(_):
if let json = response.value{
UserDefaults.standard.set(json, forKey: "token")
print("token saved \(json)")
// print((json as! [String : AnyObject]))
let homePage = self.storyboard?.instantiateViewController(identifier: "dashboard") as! HalamanUtama
self.navigationController?.pushViewController(homePage, animated: true)
}
break
case .failure(let error) :
print([error as! Error])
break
}
}
I didn't make an Interceptor class(retry and adapt) func due to the the token is not expired yet. Then, I called the token that I've already saved before in this class. Here is the code :
AF.request(url, method: .get, parameters: parameters, encoding: URLEncoding.default).responseJSON { (response) in
switch response.result{
case .success(_):
if let json = response.value{
let defaults = UserDefaults.standard
defaults.value(forKey: "token")
print("token saved \(json)")
}
break
case .failure(let error) :
print([error as! Error])
break
}
}
I got an error message : "error : 500, invalid token, data null". what's wrong with my code?
I save my login token with UserDefault. Here is the code :
I didn't make an Interceptor class(retry and adapt) func due to the the token is not expired yet. Then, I called the token that I've already saved before in this class. Here is the code :
I got an error message : "error : 500, invalid token, data null". what's wrong with my code?