问题
I have done the passwordLess email authentication. And I got the link. Now when I redirect to my app. I needs to update the user to firebase authentication. And if its success allow them to go inside my app. Same time needs to get the current logged userid.
Here is the code is used:
logic is :
- Consider I am an new user login in with email
- Consider I already logged in with my gmail account. And also authenticate already to firebase. If I am using same email address. I will get some error.
I am expecting for :
If I am fresh login ( not signin or auth before with my email id ), I need to authenticate to firebase and get the current user id. And needs to go inside app.
If iI already signedIn with my gmail account. And if I again login with my password less auth same email. Then also I needs to able to auth with firebase and login in inside my app. And get the current userid.
How can I achieve that.
My codec:
func VerifyLinkUser() {
let emailId = UserDefaults.standard.object(forKey: "Email") as! String
let link = UserDefaults.standard.value(forKey: "Link") as? String ?? "NA"
print("Url link")
print(link)
Auth.auth().signIn(withEmail: emailId, link: link) { (result, error) in
if (error == nil && result != nil) {
if( Auth.auth().currentUser?.isEmailVerified)! {
print("user verified")
}else {
print("user not verified")
}
} else {
print(error?.localizedDescription)
}
}
}
error:
"The action code is invalid. This can happen if the code is malformed, expired, or has already been used."
I followed here :
https://medium.com/@huzaifa.ameen229/firebase-email-link-authentication-ac2504068562
https://github.com/firebase/quickstart-ios/blob/master/authentication/AuthenticationExampleSwift/PasswordlessViewController.swift
来源:https://stackoverflow.com/questions/54865142/passworless-email-auth