I just upgraded my Firebase Cocoapods from 3.15.0 to 4.0.4 and FirebaseAuth Cocoapods from 3.1.1 to 4.0.0.
I'm using email & password to authenticate users. When a user changes their email I was using this method below and everything was working fine:
FIREmailPasswordAuthProviderID.credential(withEmail: emailTextField.text!, password: passwordTextField.text!)
Now that I updated I get the error message
Value of type 'String' has no member 'credential'
I looked on the docs and it said to use the method below:
The problem is I get the same exact error:
FIREmailAuthProviderID.credential(withEmail: emailTextField.text!, password: passwordTextField.text!)
Value of type 'String' has no member 'credential'
My original code below
import Firebase
import FirebaseAuth
let user: User?
let credential = FIREmailPasswordAuthProviderID.credential(withEmail: emailTextField.text!, password: passwordTextField.text!)
if let user = user{
user.reauthenticate(with: credential, completion: {
(error) in
if error != nil{
//...do something
return
}
//...do something else
})
}
What am I doing wrong?
Hold up
FIREmailAuthProviderID is a constant that contains the auth providers id and is a string (which is EmailAuthProviderID in FB 4). There is no credential function which is why you are getting that error.
Here's a link to the Firebase 4 Migration Guide
The new format (and the correct function call) is
EmailAuthProvider.credential(withEmail email: String, password:
String) -> AuthCredential
20171014 Edit: updated link to latest migration guide.
I haven't used this feature of fireBase however it appears that this link may be helpful
https://firebase.google.com/docs/reference/ios/firebaseauth/api/reference/Classes/FIREmailAuthProvider
I think you needs use EmailAuthProviderID instead of FIREmailAuthProviderID. In the Firebase 4.0 no longer uses the FIR suffix.
Hope it help you :)
Related
After I have run the required methods to unlink the password provider, it still appears when I query it using user.providerData. The FirebaseAuth-Console registers that the password providers has been unlinked, also if I run the unlink method again I get the appropriate error: "User was not linked to an account with the given provider."
Doing the same with facebook or google login runs without problems. The error only occurs if I unlink an additional password login.
Only after I logout and login again the query is correct.
All other changes are displayed immediately/correctly. Google link/unlik, facbeook unlink/link. Even the password link method is registered instantly in user.providerData, only the unlink method is not registered immediately.
Any Ideas?
Flow:
1. Query providers IDs
1.2. result -> user.providerData = facebook.com, password
2. Execute unlink "password" provider method (runs without error)
3. Query provider IDs again
3.1. ❌ result -> user.providerData = facebook.com, password
Query method:
if let user = Auth.auth().currentUser {
for profile in user.providerData {
// Id of the provider
print(profile.providerID)
}
} else {
// No user is signed in.
}
Unlink method:
Auth.auth().currentUser?.unlink(fromProvider: "password", completion: { (user, error) in
if let error = error {
print(error)
} else {
print("successfully unlinked eMail & password login")
}
})
Google has confirmed to me that this is a current bug.
They told me they were working on the issue, and will be available on the next release, but can't provide any details or exact timeline when this would be available.
So I've been trying to setup a default login system (while I create the rest of the app), so right now i just want my app to authenticate with my credentials (only 1 user, in dev), but I can't access the method the Firebase API says to use.
When I try to call the method, this is what the auto complete says
Basically, looking for a method like this
Auth.auth().signIn(withEmail: email, password: password) { (user, error) in
// code
}
Make sure you are importing both:
import Firebase
import FirebaseAuth
For sign in, Call this function and do your task inside completion handler:
FIRAuth.auth()?.signIn(withEmail: username, password: pass, completion: { (user, error) in
})
for Sign up, do this:
FIRAuth.auth()?.createUser(withEmail: "\(username)", password: "\(pass)", completion: { (user,error) in })
install angularfire2 this will solve the problem
I'm new to Firebase and iOS and I was wondering if someone knew how to link multiple oAuth Providers. I followed the Firebase docs and tried to implement this function:
func firebaseSignInWithLink(credential: FIRAuthCredential) {
FIRAuth.auth()?.signIn(with: credential, completion: { (user, error) in
if error != nil {
debugPrint("APP: there has been an error signing into firebase, perhaps another account with same email")
debugPrint("APP: \(error)")
// if existing email, try linking
FIRAuth.auth()?.currentUser?.link(with: credential, completion: { (user, error) in
if error != nil {
debugPrint("APP: there has been an error signing into firebase")
debugPrint("APP: \(error)")
}
else {
debugPrint("APP: successfully signed into firebase")
}
})
}
else {
debugPrint("APP: successfully signed into firebase")
}
})
}
The FIRAuth.auth()?.currentUser?.link function never gets called despite the above debugPrint("APP: \(error)") being called. Because this doesn't work, I keep getting the error below:
Optional(Error Domain=FIRAuthErrorDomain Code=17007 \"The email address is already in use by another account.\" UserInfo={NSLocalizedDescription=The email address is already in use by another account., error_name=ERROR_EMAIL_ALREADY_IN_USE, FIRAuthErrorUserInfoEmailKey=example#gmail.com})"
Any help would be greatly appreciated! Thank you :D
I believe you are confused by the instructions. On firebase documentation it reads
To link auth provider credentials to an existing user account:
Sign in the user using any authentication provider or method.
Complete the sign-in flow for the new authentication provider up to, but not including, calling one of the FIRAuth.signInWith methods. For example, get the user's Google ID token, Facebook access token, or email and password.
Get a FIRAuthCredential for the new authentication provider
So you should not call the method FIRAuth.signInWith. I should also point out that you want to create a link to an existing account, so you should have signed in first and then you can link it. This is why you should have a currentUser.
It occurred because of unchecking "Multiple accounts per email address setting firebase setting" from firebase console.
By following the information on this link, I am currently working on trying to create a user using Firebase, as shown in the code below. However, it appears no user is created when the app is run. Any input is greatly appreciated. The Firebase URL was taken from my test database.
let ref = Firebase(url: "https://test-96df2.firebaseio.com")
ref.createUser("bobtony#example.com", password: "correcthorsebatterystaple",
withValueCompletionBlock: { error, result in
if error != nil {
// There was an error creating the account
print("error creating account")
} else {
let uid = result["uid"] as? String
print("Successfully created user account with uid: \(uid)")
}
})
Edit:
The propagated error is:
Error Code: AUTHENTICATION_DISABLED) Projects created at
console.firebase.google.com must use the new Firebase Authentication
SDKs available from firebase.google.com/docs/auth/
However, as shown below, the email/password authentication is enabled in the Firebase console.
You have already authorized the email registration as I can see in your screenshot. So the problem doesnt realies on AUTHENTICATION_DISABLED.
From your error message and the snippet code I can see that you have created a new project but you are trying to use the legacy firebase SDK and so you will have compatibility issues. Also, you are looking into the old firebase documentation.
First of all you will need to make sure you have configured your project as documented in new firebase start guide.
After, you can take a look at the documentation for creating a new user with the new sdk. You can find the 3.x create user call bellow.
FIRAuth.auth()?.createUserWithEmail(email, password: password) { (user, error) in
// ...
}
How do I access the read permissions within the PFFacebookUtils login method? I've upgraded to Parse 1.7.3 and am using the ParseFacebookUtilsV4 framework as well. I updated the method to loginInBackgroundWithReadPermissions() and below I have the following code:
// Login through Facebook IBAction
PFFacebookUtils.logInInBackgroundWithReadPermissions(permissions, (appUser: PFUser?, error: NSError?) -> Void in
if let appUser = appUser {
let request = FBRequest.requestForMe()
request.startWithCompletionHandler { (request, user, error) -> Void in
if error == nil {
// Get Facebook user's "first_name" and set it to the newly created PFUser's "name" variable
var name = user.objectForKey("first_name") as! String
appUser["name"] = name
appUser.saveInBackgroundWithBlock({ (Bool, error: NSError!) -> Void in
})
}
}
})
I'm getting a compile-time error on FBRequest.requestForMe() saying
Use of unresolved identifier 'FBRequest'
What should I be replacing this with so that I can access the "first_name" property of the Facebook user and set it to the Parse user's "name" property I have set up?
Have you imported the Facebook SDK in your project? When you use the Parse utils, you still need to import/link it.
Also; what version of the SDK are you using? The FBRequest class is part of the 3.x series; I would advise to use the latest SDK which is in the 4.x version numbers now. Please make sure that the Parse Framework version you use matches the iOS framework used.
Instead of using FBRequest, you now use the FBSDKGraphRequest. To sure to import FBSDKCoreKit. See Parse's tutorial on github for an example request.
https://github.com/ParsePlatform/ParseUI-iOS/wiki/Integrate-Login-with-Facebook