gpt4 book ai didi

node.js - 类型错误 : "secret" is required

转载 作者:行者123 更新时间:2023-12-04 11:40:09 31 4
gpt4 key购买 nike

使用 express-openid-connect 时出现此错误

TypeError: "secret" is required
at module.exports.get (/home/mathkr/persodev/node_modules/express-openid-connect/lib/config.js:166:11)
at module.exports (/home/mathkr/persodev/node_modules/express-openid-connect/middleware/auth.js:27:18)
at Object.<anonymous> (/home/mathkr/persodev/server.js:26:9)
我的 server.js代码是
const express = require('express');
const app = express();
const port = process.env.PORT || 4200;
const {auth, requiresAuth} = require('express-openid-connect');
const dotenv = require('dotenv');
const session = require('express-session');

const sess = {
secret: 'somethingsecret',
cookie: {},
resave: false,
saveUninitialized: true
};
if (app.get('env') === 'production') {
sess.cookie.secure = true;
app.set('trust proxy', 1);
}
app.use(session(sess));

const config = {
...(dotenv.config()).parsed,
authRequired: false,
auth0Logout: true
};

app.use(auth(config));
app.use(function (req, res, next) {
res.locals.user = req.oidc.user;
next();
});

app.get('/profile', requiresAuth(), function (req, res, next) {
res.render('profile', {
userProfile: JSON.stringify(req.oidc.user, null, 2),
title: 'Profile page'
});
});

app.all('*', function (req, res) {
res.status(200).send('hello');
});

app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
请问怎么了?
版本
node 12.18.3
npm 6.14.6
yarn 1.22.4

"dotenv": "^8.2.0",
"express": "^4.17.1",
"express-openid-connect": "^2.0.0",
"express-session": "^1.17.1",

最佳答案

我在使用 Auth0 开发自己的应用程序时遇到了完全相同的问题。解决办法是到require在你之前的 dotenv require你的应用程序。这是一个示例配置:

require('dotenv').config({ path: './path/to/your/.env' });
const app = require('./app');

关于node.js - 类型错误 : "secret" is required,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64755609/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com