TypeError: "secret" is required

TypeError: "secret" is required

我在使用 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 before you require your app。这是一个示例配置:

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