Theo's Typesafe CultTTC
Theo's Typesafe Cult4y ago
3 replies
amanuel

next-auth session callback not recognizing new user property

I updated the User schema in schema.prisma like this:
model User {
  id               String    @id @default(cuid())
  name             String?
  email            String?   @unique
  emailVerified    DateTime?
  image            String?
  accounts         Account[]
  sessions         Session[]
  stripeCustomerId String?
}


and next-auth.d.ts
declare module "next-auth" {
    /**
     * Returned by `useSession`, `getSession` and received as a prop on the `SessionProvider` React Context
     */
    interface Session {
        user?: {
            id: string;
            stripeCustomerId: string;
        } & DefaultSession["user"];
    }
}


then inside [...nextauth].ts I have this:

    callbacks: {
        session({ session, user }) {
            if (session.user) {
                session.user.id = user.id;
                session.user.stripeCustomerId = user.stripeCustomerId;
            }

            return session;
        },
    },


The user.id works fine and it isn't complaining. but user.stripeCustomerId is...
I have tried:
1. Restarting TS server.
2. npx prisma generate
3. Restart VS code

Please let me know if you have stumbled upon this / know what the problem is. I am able to console.log(user.stripeCustomerId) so I know it is working.
image.png
Was this page helpful?