Firebase Cloud Function Auth触发器未触发

时间:2018-07-22 12:00:18

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

我正在Cloud Function中使用Express并使用多条路由,并且尝试添加一个函数,该函数在触发时将拉动用户Gravitar并将其添加到他们的用户对象中。

我遇到的问题是无法启动onCreate函数,并且我怀疑这与我尝试导出它的方式有关。

我的index.js如下所示:

const admin = require("firebase-admin");
const functions = require("firebase-functions");
const usersApi = require("./api/users")
const paymentsApi = require("./api/payments")
const express = require('express');
const cors = require('cors');

const app = express();

const checkHeader = async(req, res, next) => {
  if(req.headers.authorization) {
    admin.auth().verifyIdToken(req.headers.authorization)
    .then(token => {
      req.uid = token.uid;
      req.email = token.email;
      req.stripeID = token.stripeID || null;
      return next();
    })
    .catch(e => {
      return next(e.errorInfo.code)
    })
  } else {
      return next('No token found');
  }
}

app.use(cors({origin: true}));
app.use(express.urlencoded({extended: true}));
app.use(express.json());
app.use(checkHeader);

app.disable("x-powered-by");

app.use("/users", usersApi)
app.use("/payments", paymentsApi)


const setupUser = functions.auth.user().onCreate((user) => {
  console.log("onCreate")
  console.log(user)
})

module.exports = {
  api: functions.https.onRequest(app),
  setupUser
}

api端点工作正常,但是创建用户时我无法触发onCreate函数。

0 个答案:

没有答案