处理来自firebase URL验证电子邮件的传入查询参数与路由器v4作出反应

时间:2018-02-05 15:06:21

标签: reactjs email firebase firebase-authentication react-router-v4

我正在尝试使用firebase设置电子邮件验证。我可以创建用户并通过此功能发送验证。

const auth = (email , password , infoUser = {}) => (
firebaseAuth()
    .createUserWithEmailAndPassword(email,password)
    .then(user=>{
        user.sendEmailVerification(actionCodeSettings(email))
    })
)

我收到了电子邮件,它看起来像这样:

https://myappp.com/_/auth/action?mode=verifyEmail&oobCode=ueqReEeaua738p128Z36KzVTQTMmL-wu7IP_NTwLD4YAAAFhZJY4pg&apiKey=AIzaSyC51jYpiVeLUNa-FWnYUTvGrkVtN8tuiig&continueUrl=https%3A%2F%2Fautobuses-usados-mx.firebaseapp.com%2F%3Femail%3Dluissantiagodev%40gmail.com

但无法处理我的应用中的网址,它会将我发送到错误页面。

这是我使用的动作代码。

export const actionCodeSettings = (email) =>({
    url: 'https://myapp.com/?email='+email,
    handleCodeInApp: false
});

1 个答案:

答案 0 :(得分:0)

我可以解决我添加此组件的问题

    import {Redirect, Route} from 'react-router-dom'
    import React from 'react'


class AuthRequiredRoute extends Route{
    render() {
        // call some method/function that will validate if user is logged in
        {console.log(this.props.location.search)}
        if(!this.props.logged){
            return <Redirect to="/login"/>
        }else{
            return <this.props.component />
        }
    }
}

export default AuthRequiredRoute

示例:

 <AuthRequiredRoute path="/verify" component={Confirm} logged = {this.state.authed}/>

这是我的电子邮件模板中链接的结构

https://testing-app.firebaseapp.com/verify?mode=<action>&oobCode=<code>