【发布时间】:2021-08-19 04:38:15
【问题描述】:
我一直试图让 firebase 功能工作一天,但失败得很惨。
我已经使用代码从谷歌云函数内联编辑器设置了一个 http 云函数:
const admin = require('firebase-admin');
const functions = require('firebase-functions')
admin.initializeApp();
const db = admin.firestore();
exports.account_create_callable = functions.https.onCall((data,context) => {
var docRef = db.collection('users').doc(context.auth.uid)
docRef.set(
{
createdAt:Date.now(),
}, { merge: true }
);
return
})
我正在使用 React,文档非常有限,但我汇总了我认为正确的内容:
import firebase from "firebase/app";
import "firebase/auth";
import "firebase/firestore";
import "firebase/functions";
const firebase = firebase.initializeApp({
apiKey: process.env.REACT_APP_FB_API_KEY,
authDomain: process.env.REACT_APP_FB_AUTH_DOMAIN,
projectId: process.env.REACT_APP_FB_PROJECT_ID,
});
const firestore = firebase.firestore();
// require('firebase-functions'); // I saw this is some documentation but don't think it's needed?
const functions = firebase.functions()
export function createUser(uid, data) {
const account_create_callable = functions().httpsCallable('account_create_callable')
account_create_callable()
}
但是,当我运行此代码时,我在浏览器控制台中看到了一个内部错误。
Error: internal
at new HttpsErrorImpl (error.ts:65)
at _errorForResponse (error.ts:175)
at Service.<anonymous> (service.ts:276)
at step (tslib.es6.js:100)
at Object.next (tslib.es6.js:81)
at fulfilled (tslib.es6.js:71)
有趣的是,当我像这样调用不存在的函数时,我得到了同样的错误:
functions().httpsCallable('asdf')
如果有人能告诉我哪里出错了,我将不胜感激。 我的 Firebase SDK 是最新的。 我在内联编辑器中设置了函数并将我的区域设置为 eu-west 2,这会对我的客户端代码有影响吗?
【问题讨论】:
-
这能回答你的问题吗? Using non-default region for Cloud Functions
-
谢谢,我已经添加了该代码,但仍然出现内部错误
-
如果错误仍然存在,那么我们需要查看云功能端的日志。
internal的错误代码通常表示服务器端的一些未捕获/未处理的异常未包含在HttpsError中。 -
实际上我只是更改了权限以允许所有用户,现在它似乎正在工作,所以它可能是权限问题。您是否碰巧知道为什么该函数没有从上下文中获取身份验证?
-
就
allUsers权限而言?见this thread。
标签: firebase google-cloud-functions