lucia
lucia copied to clipboard
[Bug]: Lucia using Postgres via Drizzle - Date issue
Package
lucia
Describe the bug
I am migrating from SQLite to Postgres, using Drizzle. When I use the same table structure I get an error in Lucia:
TypeError: date2.getTime is not a function
at isWithinExpirationDate (file:///Users/cliftonc/work/fintune/node_modules/lucia/node_modules/oslo/dist/index.js:34:30)
at Lucia.validateSession (file:///Users/cliftonc/work/fintune/node_modules/lucia/dist/core.js:70:14)
This is because in your postgres adapter you assume the date being returned from postgres is a date:
- No transformation - https://github.com/lucia-auth/lucia/blob/main/packages/adapter-postgresql/src/base.ts#L135
- Inside Oslo you assume its a date when checking validity: https://github.com/pilcrowOnPaper/oslo/blob/main/src/index.ts#L41
- In the SQLite adatper you explicitly do the conversion: https://github.com/lucia-auth/lucia/blob/main/packages/adapter-sqlite/src/base.ts#L133
The reason this works in your tests is you use the native postgres.js, but Drizzle (for some reason) introduced a breaking change: https://github.com/drizzle-team/drizzle-orm/releases/tag/0.30.0
So my suggestion would be to check if the field is a Date, and if not try to convert it. I've made a small PR but no issue if you would prefer another path.