firebase-admin-node icon indicating copy to clipboard operation
firebase-admin-node copied to clipboard

admin.auth(...).createSessionCookie is not a function

Open silvafacundo opened this issue 8 years ago • 1 comments

  • Operating System version: Windows 10
  • Firebase SDK version: 3.18.4
  • firebase-admin: 5.8.1
  • NodeJS: v8.9.3
  • Firebase Product: Auth

I was trying to create a session cookie as documentation says and when i request '/sessionLogin' node JS return me this error (Serving from my computer)

TypeError: admin.auth(...).createSessionCookie is not a function
    at app.post (C:\Projectos\Eventos\functions\index.js:47:16)
    at Layer.handle [as handle_request] (C:\Projectos\Eventos\functions\node_modules\express\lib\router\layer.js:95:5)

This is how i handle the request

app.post('/sessionLogin', (req, res) => {  
  const idToken = req.body.idToken.toString();
  const csrfToken = req.body.csrfToken.toString();
  const expiresIn = 60 * 60 * 24 * 5 * 1000;
  admin.auth().createSessionCookie(idToken, {expiresIn:expiresIn}).then(function (sessionCookie){
    const options = {maxAge: expiresIn, httpOnly: true, secure: true};
    res.cookie('session', sessionCookie, options);
    res.end(JSON.stringify({status: 'success'}));
  }, error => {
    res.status(401).send('UNAUTHORIZED REQUEST!');
  });
});

silvafacundo avatar May 20 '18 20:05 silvafacundo

You need 5.12.0 or higher... https://firebase.google.com/support/release-notes/admin/node#5.12.0

hiranya911 avatar May 20 '18 20:05 hiranya911