问题
In my iOS/Swift/Firebase app, I am trying to access the "isNewUser" parameter after a user successfully signs in via email/password so that I can pop a window to compel them to reset their password from the temporary one initially assigned upon user creation.
Any insights would be appreciated. Thanks.
回答1:
The .isNewUser
method is available from the FirebaseAuth AdditionalUserInfo class.
Here is the link. In order to utilize this code, please see a demo sign in function I wrote below.
Auth.auth().signIn(with: credential) { (result, error) in
if let error = error{
print("Error: \(error)");
return;
}
//grabbing the user's ID info
guard let uid = result?.user.uid else {return}
//safely unwrap the boolean value rather than forcing it with "!" which could crash your app if a nil value is found
guard let newUserStatus = result?.additionalUserInfo?.isNewUser else {return}
//test the value in the debugger
print("\nIs new user? \(newUserStatus)\n")
if newUserStatus == true{
//provide your alert prompt
}
else{
//transition view to continue to the app
}
}
来源:https://stackoverflow.com/questions/53469092/ios-swift-firebase-authentication-help-needed-on-accessing-isnewuser