Node.js+中的JWT身份验证;快速图形ql+;护照

Node.js+中的JWT身份验证;快速图形ql+;护照,node.js,jwt,passport.js,express-graphql,Node.js,Jwt,Passport.js,Express Graphql,我正在使用MERN编写一个fullstack应用程序,我需要使用JWT令牌提供身份验证。我的代码如下所示: router.use(GraphQLHTTP( (req: Request, res: Response): Promise<any> => { return new Promise((resolve, reject) => { const next = (user: IUser, info = {}) => {

我正在使用MERN编写一个fullstack应用程序,我需要使用JWT令牌提供身份验证。我的代码如下所示:

router.use(GraphQLHTTP(
(req: Request, res: Response): Promise<any> => {
    return new Promise((resolve, reject) => {
        const next = (user: IUser, info = {}) => {
            /**
             * GraphQL configuration goes here
             */
            resolve({
                schema,
                graphiql: config.get("isDev"), // <- only enable GraphiQL in production
                pretty: config.get("isDev"),
                context: {
                    user: user || null,
                },
            });
        };
        /**
         * Try to authenticate using passport,
         * but never block the call from here.
         */
        passport.authenticate(['access'], { session: false }, (err, loginOptions) => {
            next(loginOptions);
        })(req, res, next);
    })
}));
router.use(GraphQLHTTP(
(请求:请求,回复:响应):承诺=>{
返回新承诺((解决、拒绝)=>{
const next=(用户:IUser,info={})=>{
/**
*这里是GraphQL配置
*/
决心({
模式,
graphiql:config.get(“isDev”),//{
下一步(登录选项);
})(req、res、next);
})
}));
我想通过GraphQL提供新一代的令牌。在这样做时,我需要检查用户是否使用了正确的身份验证方法。例如,要获得新的访问令牌,您需要刷新令牌,您需要使用刷新令牌的密码和电子邮件登录。但是使用passport意味着经过身份验证后,我将拥有一个用户


我该如何继续?

你说的“新一代令牌和通过GraphQL”是什么意思?通常在登录后,你会得到一个访问令牌和刷新令牌,之后,当访问令牌过期时,你会使用刷新令牌获得一个新的令牌。请单击“编辑”更正并澄清你的问题。@jps MERN-mongo express react nodeok,谢谢s、 不知道。@jps如果刷新令牌的生命周期结束(因为刷新令牌的生命周期也不是无限的),用户必须再次登录,然后他会收到新的有效负载。我想,我应该使用诸如getRefresh():String、signup(email:String!、password:String!):Payload、getAccess():String之类的变体。