Reputation: 131
My login with Deployd and Alamofire is working completely fine. Here is the code:
let credential = NSURLCredential(user: "username", password: "password", persistence: .ForSession)
let parameters = ["username" : "username", "password" : "password"]
Alamofire.request(.POST, "http://xxxxxxxxxxxx/users/login", parameters: parameters)
.authenticate(usingCredential: credential)
.response { request, response, _, error in
if response!.statusCode == 200 {
self.performSegueWithIdentifier("loggedIn", sender: self)
} else {
print("invalid credential bro!")
}
}
How can I check in the AppDelegate
if the user is already logged in? I am using the Deployd API on a custom server for user authentication and would like to hide the 'Login Screen' (LoginViewController
) if the user is already logged in and has an active session.
Upvotes: 1
Views: 2390
Reputation: 987
Just check if access_token
exists, like in FB API. Or you can hold it in NSUserDefaults
if you logged successfully:
if currentAccessToken != nil {
print("User logged in")
}
Upvotes: 2