You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Heroku部署NodeJS应用Facebook登录报错 连接不安全及Mongoose超时

部署在Heroku的Facebook认证NodeJS应用故障记录

问题描述

  • Facebook平台检测到关联应用未通过安全连接传输信息
  • 应用为基于NodeJS开发、采用OAuth流程接入Facebook身份认证的服务,部署于Heroku云平台
  • 运行表现差异:本地localhost环境下全流程功能正常,线上部署站点访问认证入口时流程中断
  • 线上认证入口地址为https://authenticate-backend.herokuapp.com/auth/facebook
  • 故障对应页面截图:
    输入图片描述

核心业务代码

Passport认证策略配置

passport.use(new FacebookStrategy({
    clientID: keys.facebook.clientID,
    clientSecret: keys.facebook.clientSecret,
    callbackURL: "/auth/facebook/callback",
  },
  function(accessToken, refreshToken, profile, done) {
    const { id, first_name, last_name ,name} = profile._json;
    const userData = {
      facebook_id : id,
      first_name : first_name,
      last_name : last_name,
      username : name
    };
    userModel.findOne({facebook_id:id}).then((user)=>{
        if(!user)
            new userModel(userData).save().then((newUser)=>{
                done(null,newUser)
            });
        else
            done(null,user)
    })
  }
));

认证流程路由配置

app.get('/auth/facebook', passport.authenticate('facebook'))

app.get("/auth/facebook/callback",passport.authenticate("facebook", {
      successRedirect: "/success",
      failureRedirect: "/fail"
    })
);

Heroku平台运行日志

2021-04-24T09:58:58.154550+00:00 app[web.1]: (node:4) UnhandledPromiseRejectionWarning: MongooseError: Operation `users.findOne()` buffering timed out after 10000ms
2021-04-24T09:58:58.154565+00:00 app[web.1]: at Timeout.<anonymous> (/app/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:185:20)
2021-04-24T09:58:58.154566+00:00 app[web.1]: at listOnTimeout (internal/timers.js:554:17)
2021-04-24T09:58:58.154567+00:00 app[web.1]: at processTimers (internal/timers.js:497:7)
2021-04-24T09:58:58.154668+00:00 app[web.1]: (node:4) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (rejection id: 4)
2021-04-24T09:59:17.992947+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/auth/facebook/callback?code=AQCWsZz7kdnjlF6b-4UltHiCo8nvktLXI8pwtEm65SO6DbH78h6dzTvygqZkUE2eg9WVufXyLdXUgX58_65TTb54zPWXN1sdTBTMltjO3nm_49XeWBqkcYa3qLcXUV_LwS2H_v2DpMbTTpcL5o430yHsdC3J4SF4VsXEV0tQ2E6wYgh9zMVBL-b7Omj8n_vIvLPqMlAnccP8PFMZOeV8UV0b0DovUNL8dd930aL12-x1RNdlw_yvq7G3TqpKXCq64Ny-hkNsTeSRSR0qEpiWUoC_afLMi-VoU1AiFp3gCfsWSumfQcsDWvwAv1eJDY9T48b6XP0i_u8f7FnQySExnrFl" host=authenticate-backend.herokuapp.com request_id=244f274e-ae42-4560-9f8f-078dbf987f6f fwd="116.206.223.233" dyno=web.1 connect=1ms service=30000ms status=503 bytes=0 protocol=https
2021-04-24T10:04:39.435159+00:00 heroku[router]: at=info method=GET path="/" host=authenticate-backend.herokuapp.com request_id=d30d85eb-9137-43c5-8d5f-b6bd300094f4 fwd="116.206.223.233" dyno=web.1 connect=1ms service=2ms status=304 bytes=181 protocol=https

内容的提问来源于stack exchange,提问作者Satyaki Das

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.23 17:24:03