亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Node.JS/Passport-CI-OIDC - 錯誤:發送后無法設置標頭。

Node.JS/Passport-CI-OIDC - 錯誤:發送后無法設置標頭。

莫回無 2023-07-06 17:18:50
我一直在嘗試使用passport-ci-oidc 和node.js 執行一些身份驗證。在之前的變體中,我使用了passport-idaas-openidconnect,一切對我來說都很好?,F在我收到以下錯誤:Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client    at ServerResponse.setHeader (_http_outgoing.js:470:11)    at ServerResponse.header (/Users/LSBTUser1/ibm/iERPedia/node_modules/express/lib/response.js:718:10)    at app.use (/Users/LSBTUser1/ibm/iERPedia/app.js:219:7)    at Layer.handle [as handle_request] (/Users/LSBTUser1/ibm/iERPedia/node_modules/express/lib/router/layer.js:95:5)    at trim_prefix (/Users/LSBTUser1/ibm/iERPedia/node_modules/express/lib/router/index.js:312:13)    at /Users/LSBTUser1/ibm/iERPedia/node_modules/express/lib/router/index.js:280:7    at Function.process_params (/Users/LSBTUser1/ibm/iERPedia/node_modules/express/lib/router/index.js:330:12)    at next (/Users/LSBTUser1/ibm/iERPedia/node_modules/express/lib/router/index.js:271:10)    at urlencodedParser (/Users/LSBTUser1/ibm/iERPedia/node_modules/body-parser/lib/types/urlencoded.js:91:7)    at Layer.handle [as handle_request] (/Users/LSBTUser1/ibm/iERPedia/node_modules/express/lib/router/layer.js:95:5)即使我將刪除錯誤消息中提到的行 - 我也會收到相同的錯誤,但不會提及我的代碼的任何位置(僅“/node_modules/serve-static/node_modules/send/index.js”中的錯誤)。
查看完整描述

1 回答

?
隔江千里

TA貢獻1906條經驗 獲得超10個贊

這可能是由 doAuth 中的重定向引起的。如果中間件沒有渲染任何內容,您只應該調用 next() 。這應該修復:


function doAuth(req, res, next) {

  if (req.originalUrl.indexOf('/auth/sso/callback') === 0 || req.originalUrl === '/login') {    

    return next();

  }

  if (!req.isAuthenticated()) {

    callback_url = req.originalUrl;

    return res.redirect('/login');

  }

  return next();

}

還有兩件事:


而不是使用 app.use('*', (request, response, next) => { doAuth(request, response, next); });


你可以簡單地使用app.use('*', doAuth);


并在文件開頭設置 cors 和通用標頭(否則某些路由將沒有 cors)


查看完整回答
反對 回復 2023-07-06
  • 1 回答
  • 0 關注
  • 147 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號