我正在尝试管理firebase auth会话,就像文档documentation所说的那样,但当我通过Ajax请求post方法" / loginSession"节点Js给我这个:
`error: TypeError: admin.auth(...).createSessionCookie is not a function
at app.post (C:\Projectos\Eventos\functions\index.js:48:16)
at Layer.handle [as handle_request] (C:\Projectos\Eventos\functions\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Projectos\Eventos\functions\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\Projectos\Eventos\functions\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\Projectos\Eventos\functions\node_modules\express\lib\router\layer.js:95:5)
at C:\Projectos\Eventos\functions\node_modules\express\lib\router\index.js:281:22
at Function.process_params (C:\Projectos\Eventos\functions\node_modules\express\lib\router\index.js:335:12)
at next (C:\Projectos\Eventos\functions\node_modules\express\lib\router\index.js:275:10)
at urlencodedParser (C:\Projectos\Eventos\functions\node_modules\body-parser\lib\types\urlencoded.js:82:7)
at Layer.handle [as handle_request] (C:\Projectos\Eventos\functions\node_modules\express\lib\router\layer.js:95:5)`
这是我如何管理请求
app.post('/loginSession',(req,res)=>{
const idToken = req.body.idToken.toString();
const expiresIn = 60*60*24*5*1000;
admin.auth().createSessionCookie(idToken,{expiresIn}).then((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('error');
});
});
我使用express,body-parser和firebase Firebase版本3.18.4 节点版本8.9.3
答案 0 :(得分:0)
我刚刚意识到我需要5.12.0或更高版本
答案 1 :(得分:0)
Firebase Admin SDK版本5.12中引入了createSessionCookie()
方法(以及其他会话管理方法)。请参阅changelog for the Firebase Admin SDK for Node。升级到最新版本以消除错误。