1
votes

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%[email protected]%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%[email protected]%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
            }
        }
    } 
1
It gets repeated, because an iOS fallback URL is also provided via ifl query parameter in case the app is not installed.bojeil

1 Answers

0
votes

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")
        }
      })