Firebase电子邮件验证重定向网址

时间:2018-09-06 18:44:46

标签: ios swift firebase firebase-authentication email-verification

我为我的Firebase's移动应用合并了iOS电子邮件验证,并试图解决以下问题:

  1. 重定向网址的长度显示为 extremely long。看起来像是重复自己。
  

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. 当我将handleCodeInApp设置为true时,并且当我单击重定向URL时被重定向回应用程序时,不会验证用户的电子邮件。而当我将其设置为false并通过Firebase's提供的Web小部件时,它确实得到了验证。无法找到概述快速处理前者的文档...

任何想法都值得赞赏。

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 个答案:

答案 0 :(得分:0)

确保您正在验证作为回调URL一部分的oobCode。

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

            if err == nil {

                // reload the current user
            }   
        })

完成此操作后,请在验证电子邮件后尝试从服务器重新加载用户的个人资料。

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

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

            print("email verified")
        } else {

            print("email NOT verified")
        }
      })