小编Mat*_*ler的帖子

将 Firebase 函数与 Nuxt 3 结合使用

环境

  • 操作系统:macOS 10.15.7
  • 节点版本:v16.14.2
  • Nuxt版本:3.0.0-rc.2
  • 火力地堡:9.7.0
  • firebase 管理员:10.2.0
  • firebase 功能:3.21.0
  • firebase 功能测试:0.3.3

在 firebase.json 中设置以下配置:

{
"functions": { "source": ".output/server" }
}
Run Code Online (Sandbox Code Playgroud)

我在“服务器”目录下有一个文件,其中包含以下函数:

import * as functions from "firebase-functions";

export const helloWorld = functions.https.onRequest((request, response) => {
    functions.logger.info("Hello logs!", {structuredData: true});
    response.send("Hello from Firebase!");
});
Run Code Online (Sandbox Code Playgroud)

当我跑步时:

NITRO_PRESET=firebase npm run build
firebase emulators:start --only functions
Run Code Online (Sandbox Code Playgroud)

然后转到我的 firebase 模拟器日志,它没有显示helloWorld()正在初始化的新函数。此外,当访问“http://localhost:5001/$PROJECTNAME/us-central1/helloWorld”时,它返回“函数 us-central1-helloWorld 不存在,有效函数为:us-central1-server”,这表明我的函数尚未初始化。

有什么方法可以从我的服务器目录中的文件在我的 Nuxt 3 应用程序中编写 firebase 云函数吗?

我在这里看到了类似的讨论,说可以functions在部署功能、存储、firestore 以及部署服务器和托管之间更改 nuxt.config.ts 对象。我试图仅在“服务器”目录中编写 firebase 函数,而不创建“函数”目录和项目的根目录。这可能吗?

我也在 GitHub上开启了讨论

firebase google-cloud-functions nuxt.js

6
推荐指数
1
解决办法
3038
查看次数

使用 Firebase 在 TypeScript 中导入 AuthError

使用 Firebase 时,有没有办法检查 TypeScript 中的错误是否属于“AuthError”类型。

我有一个 Https Callable 函数,它有一个 try/catch 块,其中包含以下内容:

try{
    await admin.auth().getUser(data.uid); // will throw error if user does not exist
    await admin.auth().deleteUser(data.uid);
} catch (error) {
    if(error instanceof AuthError) { // error here
        if (error.code === "auth/user-not-found") {
            logger.error(`Error: auth/user-not-found, Given user ID does not exist in Firebase Authentication`);
            throw new https.HttpsError("not-found", "Given user ID does not exist in Firebase Authentication");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但是我的 IDE 中的 if 语句会出现错误:

'AuthError' 仅指类型,但在此处用作值。ts(2693)

我正在使用import { AuthError } from …

firebase typescript firebase-authentication google-cloud-functions firebase-admin

5
推荐指数
1
解决办法
1325
查看次数