【问题标题】:node.js/express.js hosted on firebase cannot export database and authentication listeners托管在 firebase 上的 node.js/express.js 无法导出数据库和身份验证侦听器
【发布时间】:2018-06-14 22:57:15
【问题描述】:

我有一个带有 firebase 功能的 node/express 应用程序,它可以按预期响应 GET/POST 请求。但是,当我尝试附加身份验证侦听器并导出它们时,身份验证功能不会触发,即使快速服务器仍在按预期工作。我的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"
  }
}

我尝试的一切似乎都没有效果。有其他人目睹过这个问题吗?

【问题讨论】:

  • 您是否在 Firebase 控制台的“云函数”选项卡中看到 userEvents 函数?部署时,是否部署userEvents函数?
  • @Michael Bleigh 我正在使用 Firebase 服务在本地运行它。不,我没有看到。仅限应用
  • 只有 HTTP 函数能够在本地模拟 firebase serve。您需要部署您的应用才能使其他类型的触发器正常工作。
  • @MichaelBleigh 如果您在答案中发表评论,我会检查已解决。

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


【解决方案1】:

只有 HTTP 函数能够在本地使用 firebase serve 进行模拟。您将需要部署您的应用以使其他类型的触发器起作用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-17
    • 1970-01-01
    • 2017-11-04
    • 2018-07-23
    • 1970-01-01
    • 2012-09-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多