CockroachDB BigInt serialization

Hello all,

I use CockroachDB as the database driver for Prisma with BigInt ids and self-hosted dbAuth as the auth provider. When I sign up there is a new record in the User model or table but I get an error message saying “Unable to serialize BigInt”. Should I switch to String ids? CocokroachDB, unfortunately, does not support regular Int types.

Hey Hakim,

Someone may be able to chime in with more RW specific detail, but… there is quite a long discussion here around this type of issue popping up with prisma studio. There are some ‘fixes’ mentioned. Many seem to be around stringifying the data, as you suggested.

  1. Treat BigInts as strings. In your specific case, you might be able to get away with a BigInt().toString() to convert the integer into a string. That way, Express will see your BigInt as a string, and JSON.stringify will work as expected. It’ll be manual work to make sure you change all BigInts to strings, but it might be feasible, depending on what your (client-side) app wants.

Also, the latest comment (17 days ago):

Thanks for the details @kcmv!
We’ve also made some progress on this issue and will be releasing some improvements with the next Prisma release that should fix the issue in most cases.

Hey @PantheRedEye ,

I read on Prisma’s documentation that its best to use this custom implementation of JSON.stringify:
JSON.stringify( this, (key, value) => (typeof value === 'bigint' ? value.toString() : value) // return everything else unchanged )

Should I stringify the data in the api/src/functions/auth.ts file? If so where exactly?