TypeError on Signup

On signup I have this error:
2025-02-12T01:41:14.532Z ERROR [Better Auth]: TypeError [TypeError: The "payload" argument must be of type object. Received null] {
code: 'ERR_INVALID_ARG_TYPE'
}
2025-02-12T01:41:14.532Z ERROR [Better Auth]: TypeError [TypeError: The "payload" argument must be of type object. Received null] {
code: 'ERR_INVALID_ARG_TYPE'
}
I suspect it is due to the prisma schema which is
12 Replies
Devium
DeviumOP3mo ago
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model User {
id Int @id @default(autoincrement())
email String @unique
name String?
emailVerified Boolean
image String?
createdAt DateTime
updatedAt DateTime
sessions Session[]
accounts Account[]
profile Profile? // new one-to-one relation with Profile

@@map("user")
}

model Session {
id String @id
expiresAt DateTime
token String
createdAt DateTime
updatedAt DateTime
ipAddress String?
userAgent String?

userId Int
user User @relation(fields: [userId], references: [id], onDelete: Cascade)

@@unique([token])
@@map("session")
}

model Account {
id String @id
accountId String
providerId String

userId Int
user User @relation(fields: [userId], references: [id], onDelete: Cascade)

accessToken String?
refreshToken String?
idToken String?
accessTokenExpiresAt DateTime?
refreshTokenExpiresAt DateTime?
scope String?
password String?
createdAt DateTime
updatedAt DateTime

@@map("account")
}

model Verification {
id String @id
identifier String
value String
expiresAt DateTime
createdAt DateTime?
updatedAt DateTime?

@@map("verification")
}

model Profile {
id Int @id @default(autoincrement())
userId Int @unique
firstName String?
lastName String?
dateOfBirth DateTime?
address String?
gender String? // will store "Male", "Female" or "Other"
emailPersonal String?
emailWork String?

user User @relation(fields: [userId], references: [id], onDelete: Cascade)

@@map("profile")
}
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model User {
id Int @id @default(autoincrement())
email String @unique
name String?
emailVerified Boolean
image String?
createdAt DateTime
updatedAt DateTime
sessions Session[]
accounts Account[]
profile Profile? // new one-to-one relation with Profile

@@map("user")
}

model Session {
id String @id
expiresAt DateTime
token String
createdAt DateTime
updatedAt DateTime
ipAddress String?
userAgent String?

userId Int
user User @relation(fields: [userId], references: [id], onDelete: Cascade)

@@unique([token])
@@map("session")
}

model Account {
id String @id
accountId String
providerId String

userId Int
user User @relation(fields: [userId], references: [id], onDelete: Cascade)

accessToken String?
refreshToken String?
idToken String?
accessTokenExpiresAt DateTime?
refreshTokenExpiresAt DateTime?
scope String?
password String?
createdAt DateTime
updatedAt DateTime

@@map("account")
}

model Verification {
id String @id
identifier String
value String
expiresAt DateTime
createdAt DateTime?
updatedAt DateTime?

@@map("verification")
}

model Profile {
id Int @id @default(autoincrement())
userId Int @unique
firstName String?
lastName String?
dateOfBirth DateTime?
address String?
gender String? // will store "Male", "Female" or "Other"
emailPersonal String?
emailWork String?

user User @relation(fields: [userId], references: [id], onDelete: Cascade)

@@map("profile")
}
begot
begot3mo ago
log your error with error.stack to see the reason.
Devium
DeviumOP3mo ago
would i need to extend a function to log the error in the [all] api route?
begot
begot3mo ago
Hooks | Better Auth
Better Auth Hooks let you customize BetterAuth's behavior
Devium
DeviumOP3mo ago
Like this?
// src/lib/auth.ts
import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { PrismaClient } from "@prisma/client";
import { createAuthMiddleware, APIError } from "better-auth/api";

const prisma = new PrismaClient();

export const auth = betterAuth({
emailAndPassword: {
enabled: true,
},
socialProviders: {
google: {
clientId: process.env.GOOGLE_CLIENT_ID as string,
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
},
},
database: prismaAdapter(prisma, {
provider: "postgresql", // or "mysql", "postgresql", etc.
}),
hooks: {
error: createAuthMiddleware(async (ctx) => {
if (ctx.error instanceof Error) {
console.error("Error hook stack:", ctx.error.stack);
}
// Rethrow the error so that the endpoint responds with the proper error.
throw ctx.error;
}),
},
});
// src/lib/auth.ts
import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { PrismaClient } from "@prisma/client";
import { createAuthMiddleware, APIError } from "better-auth/api";

const prisma = new PrismaClient();

export const auth = betterAuth({
emailAndPassword: {
enabled: true,
},
socialProviders: {
google: {
clientId: process.env.GOOGLE_CLIENT_ID as string,
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
},
},
database: prismaAdapter(prisma, {
provider: "postgresql", // or "mysql", "postgresql", etc.
}),
hooks: {
error: createAuthMiddleware(async (ctx) => {
if (ctx.error instanceof Error) {
console.error("Error hook stack:", ctx.error.stack);
}
// Rethrow the error so that the endpoint responds with the proper error.
throw ctx.error;
}),
},
});
@begot
begot
begot3mo ago
sorry, i missed your other message - i haven't used the error hook myself, test it out and see if it behaves as expected.
Devium
DeviumOP3mo ago
No worries, it still seems to output this without a full stack
✓ Compiled /api/auth/[...all] in 438ms (1106 modules)
2025-02-12T02:38:16.277Z ERROR [Better Auth]: TypeError [TypeError: The "payload" argument must be of type object. Received null] {
code: 'ERR_INVALID_ARG_TYPE'
}
POST /api/auth/sign-up/email 500 in 1471ms
✓ Compiled /api/auth/[...all] in 438ms (1106 modules)
2025-02-12T02:38:16.277Z ERROR [Better Auth]: TypeError [TypeError: The "payload" argument must be of type object. Received null] {
code: 'ERR_INVALID_ARG_TYPE'
}
POST /api/auth/sign-up/email 500 in 1471ms
begot
begot3mo ago
could be because it's throwing ctx.error - i remember seeing this and resolving it by logging with .stack instead of throwing, can you temporarily log ctx.error.stack
bekacru
bekacru3mo ago
this is thrown from prisma. I think it's cause your Id fields are integer. Better auth expectes string Ids. If you really need to make them int instead, you'd need to disable generated Ids by setting advanced.generateId to false.
Devium
DeviumOP3mo ago
Ok thank you!
begot
begot3mo ago
the man himself got you
Devium
DeviumOP3mo ago
Than you for the advice, ill try it out :) and i love what your doing with the library

Did you find this page helpful?