I have an api (nodejs + express) running on azure webapp service and a frontend (nuxtjs) running locally and on cloudlfare. My auth flow uses passportjs LocalStrategy and worked fine when I developed it and ran the api locally. Now that I have deployed the api on azure app service, my front end always gets a 401 not authorized response. I am pretty sure it is not an issue with the frontend nuxt app since the problem occurs only when trying to use the azure hosted api.
I am using express-session with a postgres database to store session information.
const sessionPool = new Pool() //if this becomes problematic consider sessionPool.end() in logout
auth.use(session({
resave: false,
saveUninitialized: true,
secret: process.env.SESSION_SECRET,
cookie: {maxAge: 1000 * 60 * 60 * 24}, //one day
store: new (require('connect-pg-simple')(session))({
SameSite: 'none',
pool: sessionPool,
tableName: 'session'
}),
}))
Everything seems to work right at first. The user credentials get sent to the backend, they are run against the database and if they match an existing user it creates a session and CLAIMS to send the user info in the response. (some of) the cookies exist on the front end, but it seems like some are missing. When running the application locally the front end stores 5 cookies but in production it only seems to store 3. All api calls that require authorization return 401 not authorized even though the client seems to have the right information and the backend shows they have a live session (I can see the session data in the db table).
//req.isAuthenticated() always returns false on the azure web app, but true when run locally
auth.get("/user", async (req, res) => {
try {
if (req.isAuthenticated()) {
res.json({ user: req.user });
} else {
console.log("User not authenticated");
res.sendStatus(401);
}
} catch (err) {
console.log(err);
res.sendStatus(500);
}
});
I believe it is an issue with the azure app service blocking my authorization flow. The app service is using the node 16 run time and windows os (so it's using iisnode). Anyone have any insight?