The problem I am facing is down to reading a role property of a session set by the users role in a database. Why is this behaviour happening? It makes it difficult to develop new features which rely on backend control of API endpoints.
authentication code
let role = await userAuth.authUser(username, password)
if(role == null){
res.status(401).send()
}else{
req.session.role = role
req.session.save()
res.json(req.session.role)
}
This is then stored in a session table in my PSQL db. For some functions I require an admin role to be read from the session
exports.getJWT = async (req, res) => {
if (req.session.role[0].role == 'admin') {
console.log("Admin found")
}
When I send a request to this function from the same server where the express server is running it passes, and the req.session.role[0].role
can be read. However, when I am running a development environment on my localhost and I send a request to the same backend, the property is undefined and the function fails.
Here is my session code from my main express application
server.js
const sessionConfig = {
store: new pgSession({
pool: sessionDBaccess,
tableName: 'session'
}),
name: "session",
secret: "SecretsStaySecret",
cookie:{httponly:false,secure: true, sameSite: "none", expires: 12 * 60 * 60 *1000}
}