firebase - 如何获取有效的 Firebase 用户 JWT 令牌
问题描述
鉴于我有一个 Firebase 项目,但没有支持 Firebase SDK 的开发环境,我如何才能为 Firebase 项目中的一位用户获取有效的 Firebase JWT?我能够在项目中创建云函数,并尝试为此创建一个函数(在 TypeScript 中),但无济于事:
import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
admin.initializeApp();
export const login = functions.https.onRequest((req, res) => {
const email: string = req.query.email || req.body.email;
const password: string = req.query.password || req.body.password;
admin.auth().signInWithEmailAndPassword(email, password);
admin.auth().currentUser.getIdToken(true).then((idToken: any) => {
functions.logger.info("token: " + idToken, {structuredData: true});
res.status(200).send(idToken);
}).catch((error: any) => {
functions.logger
.info("could not get token: " + error, {structuredData: true});
res.status(500).send(error);
});
});
由于以下错误,此代码不会部署:
Property 'signInWithEmailAndPassword' does not exist on type 'Auth'.
Property 'currentUser' does not exist on type 'Auth'.
解决方案
推荐阅读
- php - 如何在不同文件中的 php 中写入 html 中的标签?
- excel - EXCEL 2010 条件格式问题
- amazon-s3 - AWS S3 Camel 组件的 Maven 依赖项
- java - 尽管关闭了小数宽度,但 macOS Retina 上的 OpenJDK 11 Swing 等宽字体渲染问题
- django - 第一次django_project/密码重置超时错误
- sql-server - SQL Server:按 8 个生成小时对数据进行分组
- python - os.path.splitext() 无法有效工作导致不正确的扩展输出
- java - 如何获取包含网格视图的整个列表项的单击事件?
- python - 当我在 selenium 中使用 execute_script 命令时,我不断收到 SyntaxError
- python - 从不同目录和文件中的 python 模块访问全局变量时出现问题