我正在尝试将passport.js添加到graphql端点演示
相关守则: https://gist.github.com/Falieson/855abee65621191d78575b7f28b26191#file-passport-ts-L28
loginUser mutation有效,但我希望第二次登录
context.req.user是护照信息,不是未定义的
我认为一切都在server / server.ts中正确设置
app.use(bodyParser.json());
passport.use(Passport.Collection.createStrategy())
passport.serializeUser(Passport.Collection.serializeUser())
passport.deserializeUser(Passport.Collection.deserializeUser())
app.use(
session({
secret: 'keyboard cat',
saveUninitialized: true,
resave: true,
store: new mongoStore({ mongooseConnection: mongoose.connection })
})
);
app.use(passport.initialize());
app.use(passport.session());
const rootValue = {
me: function (args: any, req: any) {
return req.user;
}
}
app.use(
GRAPHQL_REST,
bodyParser.json(),
graphqlExpress((req, res) => {
// console.log('user: ', req.user);
return {
schema,
rootValue,
context: {req}
}
})
)
我想让我知道你是否想要一个repo来重现。
答案 0 :(得分:1)
该问题与Passport或Express或我的代码无关,但与graphql-playground https://github.com/graphcool/graphql-playground/issues/576的问题