firebase上托管的node.js / express.js无法导出数据库和身份验证侦听器

时间:2018-06-14 22:57:16

标签: javascript node.js firebase firebase-authentication google-cloud-functions

我有一个node/express应用程序托管了firebase函数,它可以按预期响应GET/POST个请求。但是,当我尝试连接身份验证侦听器并导出它们时,即使Express服务器仍按预期工作,身份验证功能也不会触发。我的index.ts

const server = express();

server.get('/api' , (req : express.Request , res : express.Response ) => {
    res.send("/api endpoint");
})

exports.app = functions.https.onRequest(server);


// this even is not triggering
exports.userEvents = functions.auth.user().onCreate( user => {

    spiceAdmin.auth().createUser({
          email         : 'another-user@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}`))

});

firebase.json

{
  "database": {
    "rules": "database.rules.json"
  },
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint",
      "npm --prefix \"$RESOURCE_DIR\" run build"
    ]
  },
  "hosting": {

    "public": "public",

    // node/express application
    "rewrites": [{
        "source": "**"
      , "function": "app"  
      }],


    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  },
  "storage": {
    "rules": "storage.rules"
  }
}

我尝试的任何东西似乎都没有效果。有没有其他人目睹过这个问题?

1 个答案:

答案 0 :(得分:1)

只有HTTP功能才能在本地使用firebase服务进行模拟。您需要部署应用程序以使其他类型的触发器起作用。