Answer the question
In order to leave comments, you need to log in
How to add something to a session?
Unable to complete session. When authorizing, everything works fine, the session is saved in mysql.
But in the app.post("/addt" block, I need to somehow supplement the existing one, and for some reason the variable is not created here. How to be?
app.get("/",(request,response)=>{
if(request.session.userId && request.session.userLogin){
response.render('index');
}else{
response.render('auth');
}
console.log(request.session.tok);
});
app.post("/addt", (request,response)=>{
request.session.tok = request.body.token;
});
app.post("/auth",(request,response)=>{
user.findOne({where: {login: request.body.login}})
.then(usr=>{
if(usr.login == request.body.login && usr.password == request.body.password){
request.session.userId = usr.id;
request.session.userLogin = request.body.login;
request.session.userPass = request.body.password;
response.json({
status: true
})
}else{
response.json({
status: false
})
}
})
.catch(err=>{
response.json({
status: false
})
Answer the question
In order to leave comments, you need to log in
But in the app.post("/addt" block, I need to somehow supplement the existing one, and for some reason the variable is not created here. How to be?
in the app.post("/addt" block, I need to supplement the existingwill not work
When authorizing, everything works fine, the session is saved in mysql.
app.post("/auth",(request,response)=>{
user.findOne({where: {login: request.body.login}})
.then(usr=>{
if(usr.login == request.body.login && usr.password == request.body.password){
app.post("/addt", (request,response)=>{
request.session.tok = request.body.token; // что тут вы хотели сделать, request.body.token - в table user записать ???
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question