Next.js Discord

Discord Forum

Callback error: OAuthCreateAccount next-auth

Unanswered
Giant Angora posted this in #help-forum
Open in Discord
Giant AngoraOP
Hello, I am trying to use next-auth with drizzle adapter, I am receiving the following callback error whenever I try to log in for the first time using Google or Github providers.

error=OAuthCreateAccount

My users table in my schema is the following:

export const users = createTable('user', {
    id: varchar('id', { length: 255 }).notNull().primaryKey(),
    name: varchar('name', { length: 255 }),
    email: varchar('email', { length: 255 }).notNull(),
    emailVerified: timestamp('emailVerified', {
        mode: 'date',
        withTimezone: true,
    }).default(sql`CURRENT_TIMESTAMP`),
    image: varchar('image', { length: 255 }),
});


It is really weird because I've used next-auth before and everything worked out of the box, maybe I am missing something? This error is in my console:

[next-auth][error][adapter_error_createUser] 
https://next-auth.js.org/errors#adapter_error_createuser null value in column "id" of relation "user" violates not-null constraint {
  message: 'null value in column "id" of relation "user" violates not-null constraint'


I have another app using the same version of next-auth and same schema and this error isn't happening, any clues?

1 Reply

Giant AngoraOP
update

Changed the id field to the following:

 id: text('id')
        .primaryKey()
        .$defaultFn(() => crypto.randomUUID()),


And it worked, is this the correct way to do this now?