Using mongodb adapter and generateId creates id field in addition to _id field

using this config:
import { createId } from '@paralleldrive/cuid2'

const auth = betterAuth({
// ...
database: mongodbAdapter(client.db()),
advanced: {
generateId: () => return createId()
}
})
import { createId } from '@paralleldrive/cuid2'

const auth = betterAuth({
// ...
database: mongodbAdapter(client.db()),
advanced: {
generateId: () => return createId()
}
})
leads to user documents having the following form:
// user
{
"_id": ObjectId('67dee48723670eccd7f45380'),
"id": "g966fyld09zcrhbq7v6wiib1",
"name": " ... ",
// ...
}
// user
{
"_id": ObjectId('67dee48723670eccd7f45380'),
"id": "g966fyld09zcrhbq7v6wiib1",
"name": " ... ",
// ...
}
This seems to be intended behavior, but I would like to be able to override _id entirely. Is this possible?
1 Reply
bekacru
bekacru2w ago
jsut for mongodb adapter, we currently doesn't support a custom id generator. It should be supported soon but you can also use mongodb with prisma instead and the prisma adapter does support custom IDs

Did you find this page helpful?