Next.js Discord

Discord Forum

next-auth & prisma.io add user id to session.user object

Unanswered
Great Auk posted this in #help-forum
Open in Discord
Great AukOP
Hi. I can't seem to manage to get this to work, here's my code for the callbacks:
callbacks: {
    session: async ({ session, token }: { session: Session; token: JWT }) => {
      if (session?.user) {
        session.user.id = token.uid;
      }
      return session;
    },
    jwt: async ({ user, token }: { user: User; token: JWT }) => {
      if (user) {
        token.uid = user.id;
      }
      return token;
    },
  },

1 Reply

Great AukOP
despite adding session.user.id to my declaration typescript file, when I look at that property, it's undefined as the session object is { name: 'Tika', email: 'captika@outlook.com', image: null }