I'm new to swift so bear with me. I'm trying to store a user's token using Auth0's library A0SimpleKeychain: https://github.com/auth0/SimpleKeychain. I followed their docs and I came up with this login function:
@IBAction func login(_ sender: UIButton) {
let payload: Parameters = [
"username": self.usernameTextField.text!,
"password": self.passwordTextField.text!
]
Alamofire.request("my/url", method: .post, parameters: payload, encoding: JSONEncoding.default).responseJSON { response in
let json = JSON(response.result.value)
let token = json["token"]
let jwtToken = token.string!
A0SimpleKeychain().setString(jwtToken, forKey:"user-jwt")
let jwt = A0SimpleKeychain().string(forKey: "user-jwt")
print(jwt)
}
}
The issue I'm having it that print(jwt)
which should print the token prints nil
instead. If I print out jwtToken
then it prints out the correct value so I know it's not nil. I've tried just putting a "test" string to see if there was any issues with my jwtToken
since I'm still understanding optionals and unwrapping them but it also just returned nil.
A0SimpleKeychain().setString("testString", forKey:"user-jwt")
I'm running on OSX 10.11.6 and Swift 3