Yiğit Rüzgar
12/22/2020, 11:54 AMSwapnull
12/22/2020, 11:59 AMexport 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.Ryan
12/22/2020, 12:02 PMgetSession
method as described here:
https://next-auth.js.org/getting-started/client#getsession
https://next-auth.js.org/getting-started/client#server-side-exampleYiğit Rüzgar
12/22/2020, 12:02 PMYiğit Rüzgar
12/22/2020, 12:03 PM