lucia-auth / lucia

Authentication, simple and clean
https://lucia-auth.com
MIT License
8.96k stars 460 forks source link

[Bug]: SQLite session `expires_at` does not respect TimeSpan. #1392

Closed 8bittitan closed 7 months ago

8bittitan commented 7 months ago

Package

lucia

Describe the bug

Using the following config options:

const adapter = new DrizzleSQLiteAdapter(db, session, user);

const auth = new Lucia(adapter, {
  sessionExpiresIn: new TimeSpan(2, "w"),
  sessionCookie: {
    attributes: {
      secure: import.meta.env.NODE_ENV === "production",
    },
  },
  getUserAttributes(attributes) {
    return {
      username: attributes.username,
    };
  },
});

The expires_at column on the session table always defaults to Jan 20 1970.

This happens regardless of setting a sessionExpiresIn option. The action sessionCookie expiration adheres as expected, only the DB one is incorrect.

Bun: 1.0.25 adapter: @lucia-auth/adapter-drizzle DB: Bun SQLite

pilcrowOnPaper commented 7 months ago

Does it work properly if you don't configure the expiration?

pilcrowOnPaper commented 7 months ago

What column type are you using for expiresAt? It has to be an Int

8bittitan commented 7 months ago

No, even without the configuring the session expiration it is still giving a timestamp of 1709392662 unfortunately.

I do have the expiresAt column set to an int as below:

export const session = sqliteTable("session", {
  id: text("id").notNull().primaryKey(),
  userId: text("user_id", { length: 255 })
    .notNull()
    .references(() => user.id),
  expiresAt: integer("expires_at").notNull(),
});

I also confirmed that switching to Postgres using Neon works as expected.

pilcrowOnPaper commented 7 months ago

Timestamps are stored in seconds, not milliseconds, so 1709392662 is correct

8bittitan commented 7 months ago

Oh my 🤦. There must be something else going on on my end then. Sorry about that!