Theo's Typesafe CultTTC
Theo's Typesafe Cult3y ago
27 replies
Sam

NextAuth + DiscordProvider

I feel like I might be going about my setup wrong, but just wanted to check in. I basically want a bunch of users that are purely based on Discord accounts, and then to use their data for my Discord dashboard.

Here is my prisma user schema (rest are default)
model User {
    discordId     String    @id @unique
    name          String?
    email         String?   @unique
    emailVerified DateTime?
    image         String?
    accounts      Account[]
    sessions      Session[]
    posts         Post[]
}


The error I am getting is
Argument `discordId` is missing.
[next-auth][error][adapter_error_createUser] 
https://next-auth.js.org/errors#adapter_error_createuser 
Invalid `prisma.user.create()` invocation:

{
  data: {
    email: undefined,
    emailVerified: null,
+   discordId: String
  }
}


But can I disable this somehow?? I am overriding the signIn function so I presumed that would do it:

  async signIn({ profile }) {
      if (!profile) return false;
      const DisP = profile as DiscordProfile;

      const user = await Prisma.user.findUnique({
        where: { discordId: DisP.id },
      });

      if (!user) {
        console.log("CREATING USER", DisP.id);

        await Prisma.user.create({
          data: {
            discordId: DisP.id,
            email: DisP.email,
            // Include other properties as needed
          },
        });
      }

      return true;
    }
      }


Any ideas? This setup works fine as the database has the user ID in it fine, but its just that this is now giving me that above error. Plus, is this the best way to handle this? Seems a bit convuluted.

Thanks!
Was this page helpful?