I am using Express for my Back end of my React app when i set a session in a page and redirect to another page of my web app the session deleted
Here my express code :
async function createUser(req, res, next) {
try {
let parameters = req.body
let user = await models.User.create({
displayName: parameters.displayName,
phone: parameters.phone,
sex: parameters.sex,
password: parameters.password,
})
req.session.user = user.dataValues;
res.json({
status: 'success',
user,
})
}
and here is my react code :
onSubmit = (event) => {
event.preventDefault()
request.post('/newuser',{
displayName:this.state.name,
phone:this.state.phone,
password:this.state.password,
sex:this.state.sex
})
.then(function(response){
this.props.authenticate(true)
this.setState({
auth:true
})
}.bind(this))
}
and here is my react render method:
render(){
if(this.state.auth)
return <Redirect to='/profile' />;
}
with all this describes when i redirected to the profile page i dont have any session and all hope is gone :))
please help me solve this problem .