我正在使用https
,auth
和datastore
触发器编写firebase函数,因此我想将它们分解为不同的文件。我已经考虑了https
函数,但我不确定如何分解auth
函数。我的index.ts
目前是:
import * as express from 'express';
import * as functions from 'firebase-functions';
import { spiceAdmin } from './base';
import { spiceServer } from './spiceServer'
import { server } from './api-routes/api'
exports.app = functions.https.onRequest(server);
/**
@Use: send verification email on new user creation
*/
exports.onCreate = functions.auth.user().onCreate( user => {
spiceAdmin.auth().createUser({
email : 'user-auth-ts@gmail.com'
, emailVerified : false
, password : 'Sup3rSafe'
})
.then((userRecord : any) => console.log('created new user'))
.catch((err : string) => console.log(`failed to create new user with ${err}`))
});
具体来说,如果我的文件user_auth.ts
包含触发器onCreate
和onChange
,我将如何语法编写这些函数,然后导出,然后{{} 1}}他们在exports....
答案 0 :(得分:3)
index.ts
import { myFunction } from './myfunction'
export const myFunction_export = myFunction
myfunction.ts
import * as functions from 'firebase-functions'
export const myFunction = functions.firestore.document(...).onCreate(...)