2

I incorporated Firebase's email verification for my iOS mobile app and am trying to resolve the following issues:

  1. The length of the redirect url appears extremely long. It looks like it repeats itself.

https://app.page.link?link=https://app.firebaseapp.com//auth/action?apiKey%3XXX%26mode%3DverifyEmail%26oobCode%3XXX%26continueUrl%3Dhttps://www.app.com/?verifyemail%253Demail@gmail.com%26lang%3Den&ibi=com.app.app&ifl=https://app.firebaseapp.com//auth/action?apiKey%3XXX%26mode%3DverifyEmail%26oobCode%3XXX%26continueUrl%3Dhttps://www.app.com/?verifyemail%253Demail@gmail.com%26lang%3Den

  1. When I set handleCodeInApp equal to true, and am redirected back to the app when I click on the redirect url, the user's email is not verified. Whereas when I set it to false and go through Firebase's provided web widget, it does get verified. Wasn't able to find documentation that outlined handling the former in swift...

Any thoughts are appreciated.

func sendActivationEmail(_ user: User) {
        let actionCodeSettings = ActionCodeSettings.init()
        let redirectUrl = String(format: "https://www.app.com/?verifyemail=%@", user.email!)

        actionCodeSettings.handleCodeInApp = true
        actionCodeSettings.url = URL(string: redirectUrl)
        actionCodeSettings.setIOSBundleID("com.app.app")

        Auth.auth().currentUser?.sendEmailVerification(with: actionCodeSettings) { error in
            guard error == nil else {
                AlertController.showAlert(self, title: "Send Error", message: error!.localizedDescription)
                return
            }
        }
    } 
Chris
  • 431
  • 8
  • 33
  • 1
    It gets repeated, because an iOS fallback URL is also provided via `ifl` query parameter in case the app is not installed. – bojeil Sep 07 '18 at 02:01

1 Answers1

0

Make sure you're verifying the oobCode that is part of the callback URL.

    Auth.auth().applyActionCode(oobCode!, completion: { (err) in

            if err == nil {

                // reload the current user
            }   
        })

Once you have done that, try reloading the the user's profile from the server after verifying the email.

Auth.auth().currentUser?.reload(completion: {
        (error) in

        if(Auth.auth().currentUser?.isEmailVerified)! {

            print("email verified")
        } else {

            print("email NOT verified")
        }
      })
Padawan
  • 770
  • 1
  • 8
  • 18
  • thanks ill try it out, any thoughts on the length of the redirect url looking like it repeats itself? It's really long and I don't think it's supposed to be like that... – Chris Sep 06 '18 at 22:27
  • so i tried your answer, placing it in the appDelegate function (from docs) that handles incoming dynamic links, and it still says the email is unverified. does it have to do something with the "handleCodeInApp" versus having the Firebase web widget handle whatever code to switch the user's email to verified? – Chris Sep 06 '18 at 23:05
  • im switching to setting 'handleCodeInApp' to false and directed the user through the Firebase's web widget since it's what originally worked for me. the length of the redirect url is shorter too. – Chris Sep 06 '18 at 23:24
  • Are you verifying the oobCode parameter that is contained in the callback URL? You will need to parse it out in your appdelegate and pass it into the applyActionCode method. I updated my answer to reflect that. – Padawan Sep 06 '18 at 23:29