Unable to sign up using email / password

I keep getting this error when I sign up using email password in my next.js app
TypeError: The "payload" argument must be of type object. Received null
at async signUpAction (actions/auth.ts:26:17)
24 | export async function signUpAction(formData: FormData) {
25 | try {
> 26 | const data = await auth.api.signUpEmail({
| ^
27 | body: {
28 | name: formData.get("name") as string,
29 | email: formData.get("email") as string, {
code: 'ERR_INVALID_ARG_TYPE'
}
POST /sign-up 200 in 660ms
TypeError: The "payload" argument must be of type object. Received null
at async signUpAction (actions/auth.ts:26:17)
24 | export async function signUpAction(formData: FormData) {
25 | try {
> 26 | const data = await auth.api.signUpEmail({
| ^
27 | body: {
28 | name: formData.get("name") as string,
29 | email: formData.get("email") as string, {
code: 'ERR_INVALID_ARG_TYPE'
}
POST /sign-up 200 in 660ms
auth.ts
export const auth = betterAuth({
database: prismaAdapter(db, {
provider: "postgresql",
}),
// baseURL,
emailAndPassword: {
enabled: true,
},
plugins: [nextCookies()],
})
export const auth = betterAuth({
database: prismaAdapter(db, {
provider: "postgresql",
}),
// baseURL,
emailAndPassword: {
enabled: true,
},
plugins: [nextCookies()],
})
db.ts
const projectDir = process.cwd()
loadEnvConfig(projectDir)
neonConfig.webSocketConstructor = WebSocket
const connectionString = `${env.DATABASE_URL}`

const pool = new Pool({ connectionString })
const adapter = new PrismaNeon(pool)
export const db = new PrismaClient({ adapter })
const projectDir = process.cwd()
loadEnvConfig(projectDir)
neonConfig.webSocketConstructor = WebSocket
const connectionString = `${env.DATABASE_URL}`

const pool = new Pool({ connectionString })
const adapter = new PrismaNeon(pool)
export const db = new PrismaClient({ adapter })
21 Replies
roguesherlock
roguesherlockOP2mo ago
schema.prisma
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model User {
id String @id
email String @unique
password_hash String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String
emailVerified Boolean
image String?
sessions Session[]
accounts Account[]

@@map("user")
}

model Session {
id String @id
expiresAt DateTime
token String
createdAt DateTime
updatedAt DateTime
ipAddress String?
userAgent String?
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)

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

model Account {
id String @id
accountId String
providerId String
userId String
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")
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model User {
id String @id
email String @unique
password_hash String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String
emailVerified Boolean
image String?
sessions Session[]
accounts Account[]

@@map("user")
}

model Session {
id String @id
expiresAt DateTime
token String
createdAt DateTime
updatedAt DateTime
ipAddress String?
userAgent String?
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)

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

model Account {
id String @id
accountId String
providerId String
userId String
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")
}
cc: @bekacru
bekacru
bekacru2mo ago
you have password_hash field that's required in your user table first you should remove that. passwords are stored in the account table.
roguesherlock
roguesherlockOP2mo ago
I have not generate this schema, it's generated by better auth cli should I manually modify it?
bekacru
bekacru2mo ago
No better auth cli wouldn’t add that field.
roguesherlock
roguesherlockOP2mo ago
And when I try using it github i get this error,
GET /api/auth/get-session 200 in 217ms
GET /api/auth/get-session 200 in 55ms
POST /api/auth/sign-in/social 200 in 1118ms
GET /api/auth/get-session 200 in 26ms
2025-01-27T12:46:32.529Z ERROR [Better Auth]: unable_to_create_user
GET /api/auth/callback/github?code=afab850b423d791cd85b&state=dEI2Hz3Bi9MZ7X4qgj8ZceOElx5o_3FA 302 in 1788ms
GET /api/auth/error?error=unable_to_create_user 200 in 37ms
GET /api/auth/get-session 200 in 217ms
GET /api/auth/get-session 200 in 55ms
POST /api/auth/sign-in/social 200 in 1118ms
GET /api/auth/get-session 200 in 26ms
2025-01-27T12:46:32.529Z ERROR [Better Auth]: unable_to_create_user
GET /api/auth/callback/github?code=afab850b423d791cd85b&state=dEI2Hz3Bi9MZ7X4qgj8ZceOElx5o_3FA 302 in 1788ms
GET /api/auth/error?error=unable_to_create_user 200 in 37ms
bekacru
bekacru2mo ago
Maybe you have defined it as additional field Remove the field, push and regenerate the client
roguesherlock
roguesherlockOP2mo ago
let me just remove it and create it from scratch you were right, it removed that field! but weirdly now i get 500 error as soon as I hit my sign in page,
[TypeError: The "payload" argument must be of type object. Received null] {
code: 'ERR_INVALID_ARG_TYPE'
}
GET /sign-in?redirect=http%3A%2F%2Flocalhost%3A3000%2F 500 in 1931ms
[TypeError: The "payload" argument must be of type object. Received null] {
code: 'ERR_INVALID_ARG_TYPE'
}
GET /api/auth/get-session 500 in 105ms
[TypeError: The "payload" argument must be of type object. Received null] {
code: 'ERR_INVALID_ARG_TYPE'
}
GET /sign-in?redirect=http%3A%2F%2Flocalhost%3A3000%2F 500 in 100ms
[TypeError: The "payload" argument must be of type object. Received null] {
code: 'ERR_INVALID_ARG_TYPE'
}
GET /sign-in?redirect=http%3A%2F%2Flocalhost%3A3000%2F 500 in 1931ms
[TypeError: The "payload" argument must be of type object. Received null] {
code: 'ERR_INVALID_ARG_TYPE'
}
GET /api/auth/get-session 500 in 105ms
[TypeError: The "payload" argument must be of type object. Received null] {
code: 'ERR_INVALID_ARG_TYPE'
}
GET /sign-in?redirect=http%3A%2F%2Flocalhost%3A3000%2F 500 in 100ms
I do have a check in my page for the user and it redirect users if they're logged in. I'm assume it's failing to check for the user
export default async function SignIn() {
const session = await auth.api.getSession({
headers: await headers(),
})
if (session && session.user) {
redirect("/")
}
return (
<div className="grid h-full min-h-[80vh] place-items-center">
{/* <SignInForm /> */}
<SignInWithGithub />
</div>
)
}
export default async function SignIn() {
const session = await auth.api.getSession({
headers: await headers(),
})
if (session && session.user) {
redirect("/")
}
return (
<div className="grid h-full min-h-[80vh] place-items-center">
{/* <SignInForm /> */}
<SignInWithGithub />
</div>
)
}
bekacru
bekacru2mo ago
Have you pushed and generated the client?
roguesherlock
roguesherlockOP2mo ago
@bekacru that worked! I feel so stupid now lol thank you so much for your help! My only feedback would be that a better error messages when schema/db doesn't match better auth's schema would be nice. Other than it has been awesome experience so far from api design, feature set, tooling, docs, to support
bekacru
bekacru2mo ago
thanks and will definitely consider that!
Unknown User
Unknown User5w ago
Message Not Public
Sign In & Join Server To View
bekacru
bekacru5w ago
can you share your prisma schema
Unknown User
Unknown User5w ago
Message Not Public
Sign In & Join Server To View
bekacru
bekacru5w ago
basically the error is thrown from prisma not better auth. It happens cause when better auth tries to create a user (most likely) prisma is throwing error. First remove where you changed the model name to User. Email verified needs to be boolean field. and cross check or your remaining schema with what better auth expects in the docs.
Unknown User
Unknown User5w ago
Message Not Public
Sign In & Join Server To View
bekacru
bekacru4w ago
GitHub
better-auth-test/lib/auth.ts at main · Chandraprakash-Darji/better-...
Contribute to Chandraprakash-Darji/better-auth-test development by creating an account on GitHub.
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
bekacru
bekacru4w ago
I think it's related to the admin plugin try to signup without it the problem is enums can't be set as strings in prisma
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
bekacru
bekacru4w ago
no it returns boolean. It might be releated to the object id. Disbale the default id by setting advanced.generateId to false
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?