[Manicraft1001]
04/24/2022, 5:41 PMtypescript
const apolloServer = new ApolloServer({
schema,
debug: false,
context: ({ req, res }) => {
return {
session: req.session,
};
},
});
rp
04/24/2022, 5:54 PMverifySession
function.[Manicraft1001]
04/24/2022, 5:57 PMrp
04/24/2022, 5:58 PM[Manicraft1001]
04/24/2022, 6:00 PMrp
04/24/2022, 6:33 PM[Manicraft1001]
04/24/2022, 6:33 PMrp
04/24/2022, 6:36 PMuseSessionContext
function returns the access token payload info on the frontend (if the user is logged in).
You can set any info in the access token by following this: https://supertokens.com/docs/thirdpartyemailpassword/common-customizations/sessions/new-session[Manicraft1001]
04/24/2022, 7:13 PMSyaoran
06/18/2022, 2:28 AMconst apolloServer = new ApolloServer({
typeDefs,
resolvers,
plugins: [
ApolloServerPluginDrainHttpServer({ httpServer }),
ApolloServerPluginLandingPageGraphQLPlayground({}),
],
context: async ({ req, res}) => {
// For Session Handling
verifySession({ sessionRequired: false });
let session = await Session.getSession(req, res, { sessionRequired: false });
return {
req,
res,
session: session,
};
}
});
On the resolvers, simply access ctx.session
Sample creating session
await Session.createNewSession(
ctx.res,
payload.id,
{roles: admin},
);
@[Manicraft1001]