这是我的函数,getAccountType
import { firebaseAdmin } from './index';
export const getAccountType = async (data: any, context: any) => {
const uid = context.auth.uid;
try{
const snapshot = await firebaseAdmin.firestore().collection('users').doc(uid).get();
if(snapshot.exists){
const data = snapshot.data() as { accountType : 'youth' | 'prof', firstName : string, isProfileComplete : boolean};
return data;
}
else{
return { message : "User does not exist"};
};
} catch(e){
return { message : `Failed to get user data ${e}` };
};
};
这是我的 index.ts 文件
import * as functions from "firebase-functions";
import * as admin from 'firebase-admin';
import { helloWorld } from "./helloWorld";
import { getAccountType } from "./getAccountType";
export const firebaseAdmin = admin.initializeApp();
exports.helloWorld = functions.https.onCall(helloWorld)
exports.getAccountType = functions.https.onCall(getAccountType)
这是我收到的错误
i functions: preparing functions directory for uploading...
Error: Error occurred while parsing your function triggers. Please ensure that index.js only exports cloud functions.
HelloWorld 函数部署得很好,但出于某种原因,firebase 认为 getAccountType 不是云函数
答案 0 :(得分:1)
通过进行一些调整,我能够在 Firebase Cloud Functions 上部署您的代码。错误是说您只能导出函数。您不能导出 const
等声明。
要修复错误,请删除 index.ts 上的 firebaseAdmin
。
index.ts
import * as functions from "firebase-functions";
import { getAccountType } from "./getAccountType";
exports.getAccountType = functions.https.onCall(getAccountType)
getAccountType.ts
import * as admin from 'firebase-admin'
export const getAccountType = async (data: any, context: any) => {
// Your code logic
...
};