Is there an example with https://typegraphql.com/ ...
# support-questions
u
Is there an example with https://typegraphql.com/ and https://www.apollographql.com/ ? Session seems to be undefined all the time:
Copy code
typescript
const apolloServer = new ApolloServer({
  schema,
  debug: false,
  context: ({ req, res }) => {
    return {
      session: req.session,
    };
  },
});
r
hey @[Manicraft1001]
yes/ If you see docs for graphql, you will see how we recommend using the
verifySession
function.
r
yes
u
What does this exactly do? Does it configure that the path ``graphQL/`` uses the ``verifySession`` middleware? (It works now using the exact same code as in the documentation. I thought that I it would be different since I'm using Apollo, but no.)
r
> Does it configure that the path graphQL/ uses the verifySession middleware? Yes.
u
I was also wondering if there is a way to display & hide the user profile in the navigation when the user is logged in or out, besides using this: https://supertokens.com/docs/thirdpartyemailpassword/nextjs/session-verification/in-ssr (and making an api request each time isn't quite effient)
r
Yea.. it is! You can store the profile info in the access token and use that to fetch it on the frontend to then display the user info if they are logged in.
See this: https://supertokens.com/docs/thirdpartyemailpassword/common-customizations/sessions/checking-session-front-end The
useSessionContext
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
u
Ok, thanks for the information! Super Tokens looks super fancy so far 💪
s
I think the problem has been solved, but in case of future reference.
Copy code
const 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
Copy code
ctx.session
Sample creating session
Copy code
await Session.createNewSession(
      ctx.res,    
      payload.id, 
      {roles: admin},          
);
@[Manicraft1001]
2 Views