重构firebase函数index.ts代码,以便可以导入触发器

时间:2018-06-15 02:55:23

标签: javascript firebase firebase-authentication

我正在使用httpsauthdatastore触发器编写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包含触发器onCreateonChange,我将如何语法编写这些函数,然后导出,然后{{} 1}}他们在exports....

1 个答案:

答案 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(...)