-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Description
Issue Description
I'm trying to integrate the Facebook login/signup into my app to work alongside the standard login/signup with email. I am using Swift and have migrated to MongoDB + Parse Server (deployed on Heroku).
I've followed the Parse iOS guide on Facebook Users. However, with Parse Server, the Facebook integration isn't working normally according to all the tutorials and documentation out there. I have already looked for a solution to this issue on Stackoverflow and others (original SO post).
1. How can I link existing PFUser
s with their Facebook accounts when they log in with Facebook in the app?
I am using the Swift code from this section of the guide to associate an existing PFUser
to a Facebook account (see code below), however, this code is not executing and therefore is not linking a users existing account they created through the email sign up with their Facebook account which has the same email.
The isLinkedWithUser
method seems to require that the user be logged in. However, when a user is signed out/just downloaded the app, the PFUser.currentUser()
is nil
because the user is not logged in. Therefore, the linkUserInBackground
method won't know which PFUser
to link the Facebook account with. I believe these methods are now useless at least this case because they are meant to link after the fact (after they log in). But I don't want to create two users even if I handle this situation afterwards.
2. Is there a Cloud Code example or other Swift logic to accomplish this?
3. Has Parse addressed this issue? Should the developers use the official Facebook SDK for Facebook login? If so, how can they link existing PFUser
s to their Facebook accounts during Facebook login?
Thank you in advance for your time and patience. I greatly appreciate any help!
Code
func fbLoginButtonTapped() {
let permissions = ["public_profile", "email"]
PFFacebookUtils.logInInBackgroundWithReadPermissions(permissions, block: {
(user: PFUser?, error: NSError?) -> Void in
if let user = user {
if user.isNew {
print("User signed up and logged in through Facebook!")
} else {
print("User logged in through Facebook!")
// This API doesn't seem to be working with Parse Server
if !PFFacebookUtils.isLinkedWithUser(PFUser.currentUser()) {
PFFacebookUtils.linkUserInBackground(PFUser.currentUser(), withReadPermissions: nil, block: {
(succeeded: Bool?, error: NSError?) -> Void in
if error == nil {
print("Woohoo, the user is linked with Facebook!")
} else {
print("User is not linked with Facebook.")
}
})
}
dispatch_async(dispatch_get_main_queue(), { () -> Void in
let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("HomeNavigationController") as! UINavigationController
self.presentViewController(viewController, animated: true, completion: nil)
})
}
} else {
print("User cancelled the Facebook login.")
}
}
Expected Results
Link an existing PFUser
to a Facebook account during Facebook login.
Actual Outcome
No linking of Facebook user to existing PFUser even if the emails are the same. Two PFUsers with the same email exist, only the Facebook user has a randomly generated username (etc) because this part hasn't been implemented yet.
Environment Setup
- Server
Parse Server deployed on Heroku. - Database
mLab MongoDB.