Hello there. I have included the next-auth package...
# orm-help
y
Hello there. I have included the next-auth package in the system. How can I get the session information to resolvers (query.ts & mutation.ts) at the back? (I can easily get it in the front-end section.) https://github.com/adnanfuat/gql-askprisma
s
When creating our context, we do something like this
Copy code
export const createContext = (ctx): Context => {
  const token = ctx.req.headers.authorization.replace("Bearer ", "");

  let decodedToken = null;
  try {
    decodedToken = verify(token, config.app.jwt.secret);
  } catch (error) {
    logger.error(error);
  }

  return {
    ...ctx,
    prisma,
    user: decodedToken,
  };
};
So you can grab the auth token from the headers and decode the JWT. I don't really know how
next-auth
works, but a quick look at the docs says it works with JWTs, so I imagine it will work similarly to this. You can then do
ctx.user
in your resolver.
r
Hey @Yiğit Rüzgar 👋 I haven’t tried this but if you want to fetch the current session, you can use the
getSession
method as described here: https://next-auth.js.org/getting-started/client#getsession https://next-auth.js.org/getting-started/client#server-side-example
y
But next-auth very easy. There ara Only session variables. But problem is that I can get session esasily to front end but ı didnt way of get to backend
I tried getSession. Bu there are problems there.. I wil try again end send you errors..