making a custom id with advanced.database.useNumberId = true not working

I'm trying to create a custom int id for the user from 1 to 999999. But the problem it goes to the default and creates a user with autoIncremented id
const auth = betterAuth({
database: prismaAdapter(db, {
provider: "postgresql",
}),
advanced: {
database: { useNumberId: true },
},
databaseHooks: {
user: {
create: {
before: async (user) => {
let randomId = generateRandomInt();
// To check if there's a user with this ID
while (await db.user.findUnique({ where: { id: randomId } }))
randomId = generateRandomInt();
return {
data: {
...user,
id: randomId as unknown as string,
},
};
},
},
},
},
})
const auth = betterAuth({
database: prismaAdapter(db, {
provider: "postgresql",
}),
advanced: {
database: { useNumberId: true },
},
databaseHooks: {
user: {
create: {
before: async (user) => {
let randomId = generateRandomInt();
// To check if there's a user with this ID
while (await db.user.findUnique({ where: { id: randomId } }))
randomId = generateRandomInt();
return {
data: {
...user,
id: randomId as unknown as string,
},
};
},
},
},
},
})
3 Replies
Maqed
MaqedOP5w ago
Should I change the type of the id from int to just a string? so everything works as expected?
Ping
Ping5w ago
You can't make pass your own ID through this. useNumberId expects that your database generates the IDs.
Maqed
MaqedOP4w ago
Okay thank you!

Did you find this page helpful?