Firebase 没有部署我的函数,说它不是云函数



这是我的函数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}` };
};
};

这是我的索引。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不是云函数

通过进行一些调整,我能够在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
...
};

相关内容

  • 没有找到相关文章

最新更新