Error FAILED_TO_CREATE_USER with code 42703 when trying to create a new user

I've set up BetterAuth with my React and Vite app, and have tried to set it up with NestJS on the backend I've gotten it to not throw errors on startup, however, when I run
const register = await authClient.signUp.email({
email: values.email,
name: values.username,
password: values.password,
callbackURL: "/",
}, {
onRequest: (ctx) => {
setLoading(true);
console.log(ctx)
},
onError: (ctx) => {
setLoading(false);
console.log(ctx)
}
});
const register = await authClient.signUp.email({
email: values.email,
name: values.username,
password: values.password,
callbackURL: "/",
}, {
onRequest: (ctx) => {
setLoading(true);
console.log(ctx)
},
onError: (ctx) => {
setLoading(false);
console.log(ctx)
}
});
{response: Response, responseText: '{"code":"FAILED_TO_CREATE_USER","message":"Failed …c","line":"1065","routine":"checkInsertTargets"}}', request: {…}, error: {…}}
{response: Response, responseText: '{"code":"FAILED_TO_CREATE_USER","message":"Failed …c","line":"1065","routine":"checkInsertTargets"}}', request: {…}, error: {…}}
I won't share EVERYTHING as i dont have enough characters, so if anyone is willing to help, let me know what you need, i.e my user entity, my nestjs setup etc, and I'll send it asap
Solution:
I had a password row in my table and didnt realize I shouldnt. wasted 10h figuriing that out
Jump to solution
16 Replies
Ping
Ping3w ago
Did you receive any other errors on your server?
Josh
JoshOP3w ago
via my NestJS logs, no
Josh
JoshOP3w ago
No description
Josh
JoshOP3w ago
GitHub
GitHub - laakal/nestjs-better-auth-template: This project demonstra...
This project demonstrates how to integrate Better Auth into a NestJS application - laakal/nestjs-better-auth-template
Josh
JoshOP3w ago
I also replaced the Mongo integration with Neon DB
Josh
JoshOP3w ago
I tried to basically copy the schema https://www.better-auth.com/docs/concepts/database#user
Database | Better Auth
Learn how to use a database with Better Auth.
Josh
JoshOP3w ago
import { Collection, Entity, ManyToMany, OneToMany, OneToOne, PrimaryKey, Property } from '@mikro-orm/core';

import { generateId } from '../../util/generator';
import { FavouritedChannel } from '../channel/FavouritedChannel.entity';
import { Message } from '../message/Message.entity';
import { Server } from '../server/Server.entity';

@Entity({ tableName: 'users' })
export class User {

@PrimaryKey({ type: 'string', unique: true })
id: string = generateId(64);

@Property({ type: 'string', unique: true })
name!: string;

@Property({ type: 'string', unique: true })
email!: string;

@Property({ type: 'boolean', fieldName: "emailVerified" })
verified: boolean = false;

@Property({ type: 'string', nullable: true, fieldName: "image" })
avatar?: string;

@Property({ type: 'string' })
password!: string;

@Property()
createdAt: Date = new Date();

@Property({ onUpdate: () => new Date() })
updatedAt: Date = new Date();

@ManyToMany({ entity: () => Server })
servers = new Collection<Server>(this);

@OneToMany({ entity: () => Message, mappedBy: 'author' })
messages = new Collection<Message>(this); // FIXED: A user can have MANY messages

@OneToOne({ entity: () => Server, nullable: true, mappedBy: 'owner' })
ownedServer?: Server;

@OneToMany(() => FavouritedChannel, fav => fav.user, { orphanRemoval: true })
favouritedChannels = new Collection<FavouritedChannel>(this);

}
import { Collection, Entity, ManyToMany, OneToMany, OneToOne, PrimaryKey, Property } from '@mikro-orm/core';

import { generateId } from '../../util/generator';
import { FavouritedChannel } from '../channel/FavouritedChannel.entity';
import { Message } from '../message/Message.entity';
import { Server } from '../server/Server.entity';

@Entity({ tableName: 'users' })
export class User {

@PrimaryKey({ type: 'string', unique: true })
id: string = generateId(64);

@Property({ type: 'string', unique: true })
name!: string;

@Property({ type: 'string', unique: true })
email!: string;

@Property({ type: 'boolean', fieldName: "emailVerified" })
verified: boolean = false;

@Property({ type: 'string', nullable: true, fieldName: "image" })
avatar?: string;

@Property({ type: 'string' })
password!: string;

@Property()
createdAt: Date = new Date();

@Property({ onUpdate: () => new Date() })
updatedAt: Date = new Date();

@ManyToMany({ entity: () => Server })
servers = new Collection<Server>(this);

@OneToMany({ entity: () => Message, mappedBy: 'author' })
messages = new Collection<Message>(this); // FIXED: A user can have MANY messages

@OneToOne({ entity: () => Server, nullable: true, mappedBy: 'owner' })
ownedServer?: Server;

@OneToMany(() => FavouritedChannel, fav => fav.user, { orphanRemoval: true })
favouritedChannels = new Collection<FavouritedChannel>(this);

}
and ofc i have some of my own stuff altho i havent added an accounts table or a session table not sure if i need to do that or if it does it itself
Ping
Ping3w ago
You should just run the better auth schema generation if possible.
Josh
JoshOP3w ago
iis it possible to run it so it generates an entity for nest though? oh wait it generates a Kyseley sql fiile which i assume i can just use as a migration
Ping
Ping3w ago
Yeah
Josh
JoshOP3w ago
lemme see if thatll work oh wait it needs an auth.ts file or a config file which nestjs doesnt have
Ping
Ping3w ago
You can just make a fake one with the same configurations as your apps.
Josh
JoshOP3w ago
I still get the same error :shrug:
Josh
JoshOP3w ago
No description
Josh
JoshOP2w ago
oh wait nhvm im beiing dumb so now, when i run something like
const register = await authClient.signUp.email({
name: 'Test',
password: 'test_password',
});
const register = await authClient.signUp.email({
name: 'Test',
password: 'test_password',
});
the password is set to null and its trying to push it Failing row contains (gXZB6hU29dYk8aamkdMCP6avCbvElEfG, Test, [email protected], f, null, null, 2025-05-04 13:35:01.657+00, 2025-05-04 13:35:01.657+00). id, name, email, emailVerified (i assume f means false), password, image, createdAt, updatedAt so for some reason when running signUp.email, password is null bump so my users table matches the schema from https://www.better-auth.com/docs/concepts/database#user
import {
createAuthClient,
} from 'better-auth/react';

export const authClient = createAuthClient({
baseURL: 'http://localhost:3000',

});

export const {
signIn,
signOut,
signUp,
useSession,
} = authClient;
import {
createAuthClient,
} from 'better-auth/react';

export const authClient = createAuthClient({
baseURL: 'http://localhost:3000',

});

export const {
signIn,
signOut,
signUp,
useSession,
} = authClient;
my nestjs setup is the exact same as the github repo i linked above oh my god i figured it out oh my god i hate my life
Solution
Josh
Josh2w ago
I had a password row in my table and didnt realize I shouldnt. wasted 10h figuriing that out

Did you find this page helpful?