Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift3 iOS -Firebase FIREmailPasswordAuthProvider Not Working

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:

enter image description here

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?

like image 908
Lance Samaria Avatar asked Jul 16 '17 04:07

Lance Samaria


1 Answers

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.

like image 147
Jay Avatar answered Nov 12 '22 06:11

Jay