1

In my web application, there is a page "interfacePage" which I want to restrict access to (server-side). So I am using a function every time the page is called to get a firebase session cookie from client cookies which is then checked for validity. If valid, interfacePage is rendered, otherwise login page is.

Code snippet

function isAuthenticated(req, res, next){
try {
    var sessionCookie = req.cookies.session;
    console.log(sessionCookie);
    admin.auth().verifySessionCookie(sessionCookie, true)
        .then(function(decodedClaims){
            console.log("token verified");
            next()
                })
        .catch(function(error){
            console.log(error);
            res.redirect('/users/login');
            });
    }catch (err)
    {
        console.log(err);
    }
};

router.get('/interfacePage', isAuthenticated,function (req, res, next) {
//isAuthenticated is called when this get is called. If next() is called from isAuthenticated, then function (req, res, next) is called which renders page
res.render('interfacePage');
});

This code works PERFECTLY FINE locally. But once I deploy it and launch the app through firebase console, it keeps giving me Gateway Timeout error whenver I request interfacePage. I think it's probably

admin.auth().verifySessionCookie(sessionCookie, true)

taking too long to respond for some reason.

Any assitance would be appreciated.

Mohamed Moustafa
  • 377
  • 4
  • 18

1 Answers1

0

Ok, so apparently firebase strips all cookies except cookies with "__session" name. I changed the name of the cookie from session to __session and it works now.

Mohamed Moustafa
  • 377
  • 4
  • 18