Next.js Discord

Discord Forum

Updating the JWT on new-user

Unanswered
Cape lion posted this in #help-forum
Open in Discord
Cape lionOP
Im switching to the JWT strategy and i have some logic that runs on my new user page


export const authOptions: NextAuthOptions = {
  debug: env.VERCEL_ENV === "development" || env.VERCEL_ENV === "preview",
  session: {
    strategy: "jwt",
  },
  callbacks: {
    async jwt({ token, user }) {
      if (user) token.user = user as Session["user"];
      return token;
    },
    async session({ session, user, token }) {
      return token;
    },
    async signIn({ user, account, profile, email, credentials }) {
      const params = { user, account, profile, email, credentials };
      return await onSignin(params);
    },
  },
  adapter: PrismaAdapter(prisma),
  providers: [
  ],
  pages: {
    signIn: "/",
    newUser: "/auth/new-user",
  },
};

export default NextAuth(authOptions);

/// new-user
...
const { team, user } = await createNewTeamForNewUser({
      teamName: session.user.email as string,
      userId: session.user.id,
    }); // gets created in the database but not added to the JWT

    return redirectTo(`/dashboard/${team?.slug}/welcome`);


How do i add the team to the JWT?

0 Replies