I am trying to set up session cookies in my Node server, which is the backend for an Electron app. I am trying to follow this guide.
https://firebase.google.com/docs/auth/admin/manage-cookies
The first thing I am confused about is where this function comes from in the "Sign In" section: const csrfToken = getCookie('csrfToken')
Is 'getCookie' a function I am supposed to write myself?
I am also not fully following the logic of the "create session cookie" snippet:
const csrfToken = req.body.csrfToken.toString();
// Guard against CSRF attacks.
if (csrfToken !== req.cookies.csrfToken) {
res.status(401).send('UNAUTHORIZED REQUEST!');
return;
}
So this looks like it's checking to see if the request body's CSRF token is the same thing set in the request cookie's CSRF token? Is this because someone might set the CSRF token manually (i.e. using Postman) but such a request won't go through because it's not in req.cookies
? Does this imply that one is not supposed to be setting req.cookies in their client-side code?