I've been receiving this error "An internal error has occurred, print and inspect the error details for more information" when trying to login through the access-token I receive from Github.
let credential = FIRGitHubAuthProvider.credentialWithToken(accessToken)
FIRAuth.auth()?.signInWithCredential(credential) { (user, error) in
if let error = error {
print(error.localizedDescription)
}
}
It seems the issue is happening here but I'm not so sure why. Thank you in advance!
Related
I finally decided its time for testflight with my app. Authentication works perfectly in the simulator. I've tried it with test numbers (works great), I've tried it with my phone (sends verification code), and I've tried it with my parents phone (a device that has never been set up with my firebase) and it worked great.
As soon as I set it up on my device and tried to authenticate the same way, I encountered an error
here is the very simple code I took straight from firebase docs
public func startAuth(phoneNumber: String, completion: #escaping (Bool) -> Void) {
PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumber, uiDelegate: nil) { [weak self] verificationId, error in
guard error == nil else {
print("error verifying phone numer, Error: \n\(error!)")
completion(false)
return
}
self?.verificationId = verificationId
completion(true)
}
}
When running in the simulator, it works great, when running on my phone, I get this error:
error verifying phone numer, Error:
Error Domain=FIRAuthErrorDomain Code=17999 "An internal error has occurred, print and inspect the error details for more information." UserInfo={FIRAuthErrorUserInfoNameKey=ERROR_INTERNAL_ERROR, NSLocalizedDescription=An internal error has occurred, print and inspect the error details for more information., NSUnderlyingError=0x283f43c30 {Error Domain=FIRAuthInternalErrorDomain Code=3 "(null)" UserInfo={NSUnderlyingError=0x283f9bae0 {Error Domain=com.google.HTTPStatus Code=503 "(null)" UserInfo={data={length = 207, bytes = 0x7b0a2020 22657272 6f72223a 207b0a20 ... 5d0a2020 7d0a7d0a }, data_content_type=application/json; charset=UTF-8}}, FIRAuthErrorUserInfoDeserializedResponseKey={
code = 503;
errors = (
{
domain = global;
message = "Error code: 33";
reason = backendError;
}
);
message = "Error code: 33";
}}}}
I've tried adding the firebase auth SDK: https://github.com/firebase/firebase-ios-sdk to the project and I get an error in a random file that says "redfinition of module 'Firebase'" and other stack overflow posts say to just delete the SDK and it'll solve your issue.
I'm really confused, why does it only work in the simulator and not my device?
Is the SDK really the solution and I need to find another way around the redefinition issue?
Thanks for your help in advance!
I'm trying to create an "update email" screen for an iOS app, using Xcode Version 10.2.1 and Firebase. All of the code for updating the email with Firebase works fine, but I'm getting the following error when I try to reauthenticate the user:
Cannot convert value of type '(_) -> ()' to expected argument type 'AuthDataResultCallback?' (aka 'Optional<(Optional, Optional) -> ()>')
Oh, and I'm using Email credentials to Auth users.
I've searched multiple threads here and scoured through the Firebase documentation and can't seem to figure out what is causing this error.
Here's my code, which I pulled from the Firebase Documentation, as well as this thread:
let user = Auth.auth().currentUser
var credential: AuthCredential = EmailAuthProvider.credential(withEmail: "email", password: "pass")
user?.reauthenticate(with: credential) { error in
if let error = error {
// error handled here
} else {
// success
}
}
The error is showing up on the "user?.reauthenticate(with: credential) { error in " line.
Anyone have any idea what is causing this?
(And, apologies if I'm missing something obvious. I'm relatively new to working with Swift/Xcode. )
THANKS!!
I think you're missing the result parameter
let user = Auth.auth().currentUser
var credential: AuthCredential = EmailAuthProvider.credential(withEmail: "email", password: "pass")
user?.reauthenticate(with: credential) { result, error in
if let error = error {
// error handled here
} else {
// success
}
}
where result is an AuthDataResult that contains the result of a successful signin.
Auth.auth().signIn(withEmail: emailTextField.text!, password: passwordTextField.text!)
{ (user, error) in
if error != nil {
print(error!)
self.warningLabel.isHidden = false;
self.passwordTextField.text = "";
} else {
print("Log in succesful")
self.performSegue(withIdentifier: "welcomeSeg", sender: self)
}
}
Whenever I sign in or sign up a user I just print a generic warning label instead of the actual issue. I print the error I receive and it's too verbose to show to the user.
Error Domain=FIRAuthErrorDomain Code=17009 "The password is invalid or the user does not have a password." UserInfo={NSLocalizedDescription=The password is invalid or the user does not have a password., error_name=ERROR_WRONG_PASSWORD}
Error Domain=FIRAuthErrorDomain Code=17008 "The email address is badly formatted." UserInfo={NSLocalizedDescription=The email address is badly formatted., error_name=ERROR_INVALID_EMAIL}
Is there any way to fetch the error code so I can be more specific with my error messages? I've looked through the documentation but have been unsuccessful in coming up with anything.
I would recommend creating an AuthErrorCode object (provided by the Firebase SDK) from the error you receive and using that as you see fit. If I remember correctly, AuthErrorCode is an enum with cases like .wrongPassword, .invalidEmail, etc.
A simple pseudocode example:
if error != nil {
if let error = AuthErrorCode(rawValue: error?.code) {
switch error {
case .wrongPassword:
// do some stuff with the error code
}
}
Also, I feel your pain. I've found that the Swift SDK documentation lags quite a bit when changes come along.
I'm not able to understand why neither print lines are executed when running the following code:
ref.child("schools/\(schoolTextField.text!)/settings/pin").observeSingleEvent(of: .value, with: { (snapshot) in
print(snapshot.value)
}, withCancel: { (error) in
print(error.localizedDescription)
})
It used to work, until I made some changes regarding firebase authentication, but I don't see why the withCancel block is not executed!
How do I catch whatever error is occuring here? No error-message is printed in the log.
EDIT:
I found a similar question here which suggests that the problem might be related to the authentication after all. In appDelegate's didFinishLaunchingWithOptions I check if the user auth-token exists in Firebase Auth:
Auth.auth().currentUser?.getIDTokenForcingRefresh(true, completion: { (response, error) in
guard error == nil, let uid = response else {
print(error)
return
}
...
})
In current case there is an error, which is printed:
Error Domain=FIRAuthErrorDomain Code=17011 "There is no user record corresponding to this identifier. The user may have been deleted."
I'm now also getting these errors printed in the log:
[Common] _BSMachError: port b43b; (os/kern) invalid capability (0x14) "Unable to insert COPY_SEND"
[Common] _BSMachError: port b43b; (os/kern) invalid name (0xf) "Unable to deallocate send right"
Try this way:
if let snapshot = snapshot.children.allObjects as? [DataSnapshot] {
for snap in snapshots {
print("SNAP: \(snap)")
}
Also The error code 17011 is a user not found error see FIRAuthErrorCode for more info also it's better you create a Dataservice class to handle your interaction with firebase see Creating A Reusable Firebase Data Service for more info.
I am using the latest Facebook SDK and I get this error when I run the block of code below: Facebook signup error - The operation couldn’t be completed. (com.facebook.sdk.login error 308.)
Here is my code:
func signupWithFacebook() {
FBSDKLoginManager().logIn(withReadPermissions: ["public_profile"], from: self) { (result, error) in
if let error = error {
print("Facebook signup error - \(error.localizedDescription)")
} else if result != nil {
let credential = FIRFacebookAuthProvider.credential(withAccessToken: FBSDKAccessToken.current().tokenString)
self.facebookSignup = true
self.addUserToAuth(credential, twitterUserID: "")
}
}
}
I Figured it out! It has to do with the way Apple deals with Keychain. All you have to do is go into the "Compatibilities" tab under the target for your app and turn "Keychain Sharing" on. Here is a more fulfilling answer.