-
-
Notifications
You must be signed in to change notification settings - Fork 495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: date.getTime() is not a function (originating in oslo) -> but the core problem is that nodejs-adapter from Lucia doesn't convert expiresAt as a date #1424
Comments
What version of |
EDIT: Sorry I saw that
|
Can you share your Drizzle/db schema? There's also a new Drizzle adapter https://lucia-auth.com/database/drizzle |
I don't think the
Here is the SQL to verify that the column is defined as expected. SELECT column_name, data_type FROM information_schema.columns where table_schema = 'public'
and table_name = 'session';
None the less here is the drizzle db schema definition on top of it (which at the moment Lucia should have no awareness off, but will try using the drizzle adapter so that I can start the app properly). export const session = pgTable('session', {
id: varchar('id', {
length: 128
}).primaryKey(),
userId: varchar('user_id', {
length: 15
}).notNull()
.references(() => authUser.id),
expiresAt: timestamp('expires_at', { mode: 'date' }).notNull()
}); |
I can confirm that using
The |
Hm, that's weird since everything is tested |
False positive test - has to be from what I've been observing. None the less I will check out the repository today or tomorrow and try to replicate the test (or explain why is it falsely positive). |
Hm yeah the tests are fine. Can you try setting |
Do you mean in the |
Yes, in |
As I said, the problem can't be with
|
I just checked here -> and I see no EDIT: found it lucia/packages/adapter-test/src/index.ts Line 36 in af2e489
|
Just a small update, I managed to checkout the Lucia repo -> and I can verify that the test works. Trying to find now what is the discrepancy between my project and the setup - or potentially some other It's Valentines Day so I guess I have nothing better to do. 🤣 |
After a lot of digging I found the source of my issue -> and I think the docs should warn of this. If you use See source code for Mystery solved. @pilcrowonpaper shout if you agree on the docs and if you would accept a PR |
Oh wow, that's sneaky. Yeah it should be probably mentioned in the docs - I guess at the top of the PostgreSQL database page. |
I've encountered this as well and thank you for your contribution to the docs! |
Literally just hit this one as well 😅 Thanks @callmeberzerker @pilcrowonpaper it might be worth fixing this at the adapter level or at the oslo level (accept string) as this could happen with other ORMs, not only Drizzle. Something like this would work : |
For me, this is the solution: change the timestamp options.mode from "string" to "date". From this:
To this:
So the session table schema will look something like this:
|
I was also only able to fix this by using |
Yeah it's an issue with Drizzle since they override your driver's default date behavior |
Getting the same error using Neon + Fixed using: class CustomNodePostgresAdapter extends NodePostgresAdapter {
override async getSessionAndUser(
sessionId: string
): ReturnType<
(typeof NodePostgresAdapter)['prototype']['getSessionAndUser']
> {
const [session, user] = await super.getSessionAndUser(sessionId);
if (session) {
session.expiresAt = new Date(session.expiresAt);
}
return [session, user];
}
} |
Package
@lucia-auth/adapter-postgresql
Describe the bug
So my first time deep delving into the codebase of Lucia so bear with me:
expires_at
is timestamp in the database with timezone.this.adapter.getSessionAndUser(sessionId);
-> which will in turn go the database, fetch the session, convert thefields_with_underscores
tofieldsWithUnderscores
(ie.expires_at
->expiresAt
).oslo
to check if the sessionisWithinExpirationDate
-> but theexpiresAt
has been loaded as astring
even though it is defined as a timestamp with zone.I am using the following adapter for Postgres
Here is how the database session looks like when loaded from the db by lucia.
Here is the stack trace where it fails ultimately:
This is a severe issue I can't circumvent since upgrading (still in progress obviously) to v3. Any insight into this issue is more than welcomed. 🙏
The text was updated successfully, but these errors were encountered: