NextAuth: How do I get the JWT Session Token (undecoded) on the client?

Viewed 30

I've tried getting the session token from the next-auth.session-token cookie, but failed to get the value of the cookie (even after using multiple libraries).

I tried passing token along with the session when forming the session object, but it seems to return the decoded token instead of the raw JWT token text.

I need the JWT token to be able to send it across to another service that I need to authenticate with (Hasura, through URQL).

Right now, I have a hack set up: I have created an API /api/me which returns the token for the currently logged in user.

import type { NextApiRequest, NextApiResponse } from "next";
import { getToken } from "next-auth/jwt";

export default async (req: NextApiRequest, res: NextApiResponse) => {
  const token = await getToken({ req, raw: true });

  res.status(200).json({ token });
};

and then I instantiate the urql client from the response of this API, but I don't want to spend precious ms making another fetch.

How do I get the JWT Session Token (undecoded) on the client?

0 Answers
Related