【发布时间】:2019-03-04 04:19:32
【问题描述】:
我正在尝试将 jwt express 中间件和 postgraphile 中间件一起使用,并且我想添加一个例外,以便在 graphiql 界面中使用身份验证令牌。我知道 postgraphile 在 /graphql 上启动 graphql,在 /graphiql 上启动 graphiql,除非另有配置。所以在我的 jwt 中间件初始化中,我正在这样做:
app.use(jwt({ secret: process.env.JWT_SECRET}).unless({path: ['/', /\/graphiql/i, /\/graphql/i, /auth/i]}));
这使得 /graphiql、/graphql 和 /auth 路由不需要身份验证令牌。这似乎工作正常,因为我可以很好地进入 graphiql 界面,并且我正在构建的 graphql 查询工作得很好。但是,在我的快递终端中,当我加载 http://localhost:3000/graphiql 时,它仍然试图连接到一个 No authorization token found
对于我还必须添加到 JWT 中间件中的 unless() 方法中的其他内容有什么想法吗?
【问题讨论】:
标签: node.js express jwt graphql