Redux状态不会持久

时间:2018-05-11 09:11:08

标签: reactjs authentication redux nodes

我正在尝试重置用户密码(忘记密码)

为此我正在做

  1. 获取用户的电子邮件(在redux商店中设置电子邮件)

  2. 发送指向该邮件的链接

  3. 在该链接获取新密码(来自redux商店的电子邮件)
  4. 问题是在我在redux商店中设置电子邮件后,当我打开发送到邮件的链接时,我无法从商店获得该值。

    我的商店在该链接显示其他值,但不是我在第二步之前设置的电子邮件

    从用户

    获取电子邮件地址的第一步
    ....
    
                this.props.setEmail(this.state.email)
    axios.post('/forgetEmail/',{"email":this.state.email})
                    .then((res)=>{
                    console.log(res)
                })
    ....
    
    var mapDispatchToProps = (dispatch)=>{
        return{
            setEmail:(data)=>dispatch({type:'SET_USER_EMAIL',payload:data})
        }
    }
    
    export default connect((state)=>{return state},mapDispatchToProps)(Footer)
    

    我的减速机

    import jwt from 'jsonwebtoken'
    import axios from 'axios'
    
    export default function AuthReducer(state={isAuth:false},action){
    
    
    
     ...
    else if(action.type === 'SET_USER_EMAIL'){
                console.log("dsdasd")
                console.log("seting email",action.payload)
                return Object.assign({},state,{email:action.payload})
            }
            return state
        }
    

    请求

    Router.get('/passWordForget/:param1',(reqs,resp)=>{
        console.log("heh")
        console.log(reqs.params)
        resp.statusCode = 302;
        var token = reqs.params.param1
    
        jwt.verify(token,"aseceratetoken",(err,decoded)=>{
            if(err){
                resp.setHeader("Location", `http://localhost:3000/`);
            }else{
                reqs.cookie('vstring',token)
                resp.setHeader("Location", `http://localhost:3000/#/newPassword/`);
            }   
        })
      resp.end();
    })
    

    获取新密码(此处 this.state.user.email未定义

    constructor(props){
                super(props)
    
    
    
            this.state = {
                email:this.props.user.email,
                password:'',
                passwordVerify:''
            }
            this.handleChange = this.handleChange.bind(this)
            this.handleSubmit = this.handleSubmit.bind(this)
        }
    var mapStateToProps = (state)=>{
        return {
            user:state.Auth
        }
    }
    
    export default connect(mapStateToProps)(NewPass
    
    )
    

    我的combine reducer / rootReducer文件

    import {createStore, combineReducers} from 'redux'
    
    import Auth from './Auth.js'
    import {loadState} from './loadState.js'
    
    const presistState = loadState()
    
    var rootReducer = combineReducers({
        Auth
    })
    
    export default rootReducer
    

    我花了很多时间寻找解决方案,欢迎任何帮助,谢谢你。

0 个答案:

没有答案