Auto Cleanup for expired verification data - fails on D1 (also sqlite?)

Using better-auth on Cloudflare D1. Since updating to better-auth 1.2, authentication fails with errors as follows:
(log) Query: delete from "auth_verifications" where "auth_verifications"."expiresAt" = ? -- params: ["2025-03-02T14:23:00.936Z"]
(error) # SERVER_ERROR: Error: D1_TYPE_ERROR: Type 'object' not supported for value 'Sun Mar 02 2025 14:23:00 GMT+0000 (Coordinated Universal Time)'
(log) Query: delete from "auth_verifications" where "auth_verifications"."expiresAt" = ? -- params: ["2025-03-02T14:23:00.936Z"]
(error) # SERVER_ERROR: Error: D1_TYPE_ERROR: Type 'object' not supported for value 'Sun Mar 02 2025 14:23:00 GMT+0000 (Coordinated Universal Time)'
This can be reproduced on Cloudflare D1, when using the proposed fix in this PR which fixes insertions into verifications, but not the cleanups. It may also affect sqlite directly, when using the kysely-adapter instead of the drizzle-adapter. Essentially, the field values in where clauses are not being transformed as supported by Cloudflare D1. Workaround exists, when instantiating betterAuth:
verification: {
disableCleanup: true,
},
verification: {
disableCleanup: true,
},
Expected behaviour would be auto-cleanup working for Cloudflare D1 without error.
GitHub
Transform sqlite values in Drizzle adapter. by RyanNieuwoudt · Pull...
Not sure whether this is considered a fix or a new feature, depending on whether better-auth officially supports sqlite via drizzle-adapter. In this configuration, authentication does not work. Ins...
Cloudflare Docs
Workers Binding API · Cloudflare D1 docs
You can execute SQL queries on your D1 database from a Worker using the Worker Binding API. To do this, you can perform the following steps:
2 Replies
bekacru
bekacru2d ago
doesn't drizzle handle the conversion itself?
Ryan Nieuwoudt
Ryan NieuwoudtOP2d ago
It does not. The only mention of D1_TYPE_ERROR in the Drizzle channel is here.

Did you find this page helpful?