'I can not set a token FIrebase
app.post('/authenticate', async function(req, res){
const secret="secret"
const { username, password } = req.body;
var passwordToCheck = await getData("users","admin");
passwordToCheck=passwordToCheck.password;
checkPassword(password, passwordToCheck, function (err,same) {
if(err){
console.log("Internal error")
res.status(500)
.json({
error: 'Internal error please try again'
});
}else if(!same){
console.log("Wrong Email")
res.status(401)
.json({
error: 'Incorrect email or password'
});
}else{
const payload = { username };
const expiresIn = 60 * 60 * 24 * 5 * 1000;
const options = { maxAge: expiresIn, httpOnly: true, secure: true, path: "/"};
const token = jwt.sign(payload, secret, {
expiresIn: '1h'
});
res.setHeader('Cache-Control', 'private');
res.cookie('__session', token, options).sendStatus(200);
}
});
});
So this code works when running locally but not when I deploy it. The cookie will not be set and I cant figure out why. My backend is hosted using firebase functions and my frontend is hosted with firebase hosting. Thanks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
