I do a POST ajax request when user clicks sign in. In the handler:
app.post('/auth', function(req,res,next){
var token = req.body.token
session({ secret: 'keyboard cat', cookie: { maxAge: 60000*60*24 }})
admin.auth().verifyIdToken(token)
.then(function(decodedToken) {
res.send({userID: decodedToken.uid})
}).catch(function(error) {
console.log(error.message)
})
})
I am using express-session. My question is why does this cookie not get saved to the user's computer? I tested it out and it's not working.
I'm pretty sure you'd need to initialise your session middleware before any routes.
app.use(session({
secret: "keyboard cat",
cookie: {
maxAge: 60000*60*24
}
}));
app.post("/auth", (req, res) => {
const token = req.body.token;
admin
.auth()
.verifyIdToken(token)
.then((decodedToken) => {
res.send({userID: decodedToken.uid})
}).catch((error) => {
console.log(error.message)
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.