Giter Club home page Giter Club logo

Comments (4)

pilcrowOnPaper avatar pilcrowOnPaper commented on September 28, 2024 1

This should probably be a bug report?

from lucia.

pilcrowOnPaper avatar pilcrowOnPaper commented on September 28, 2024

Have you tried using the SQLite Drizzle adapter provided by @lucia-auth/adapter-drizzle?

from lucia.

jasperkelder avatar jasperkelder commented on September 28, 2024

Only rudimentary, I just now gave it a more thorough go. When making the switch I'm importing the DrizzleSQLiteAdapter from it, and I'm changing the old LibSQL setup (https://lucia-auth.com/database/sqlite):

const adapter = new LibSQLAdapter(db, { user: "user", session: "session"});

Into the DrizzleSQLite setup (https://lucia-auth.com/database/drizzle):

const adapter = new DrizzleSQLiteAdapter(db, sessionTable, userTable);

Something to be noted is that in this code I actually need to pass the libSQLClient to the adapter in the LibSQL setup instead of the db. For the DrizzleSQLite setup I'm switching to the actual db to make it work. For reference this is how both are configured:

export const libSQLClient = createClient({
	url: env.DATABASE_URL,
	authToken: env.DATABASE_AUTH_TOKEN
});

export const db = drizzle(libSQLClient, { schema });

After doing so I'm encountering a sessionTable type mismatch for the expiresAt column. The dataType is expected to be "number" but is interpreted as "date". I'm able to resolve this for now by removing the { mode: 'timestamp' } configuration from my Drizzle sessions table:

export const sessions = sqliteTable('sessions', {
	id: text('id').primaryKey(),
	userId: text('user_id')
		.references(() => users.id, { onDelete: 'cascade' })
		.notNull(),
	expiresAt: integer('expires_at', {
		mode: 'timestamp'
	}).notNull()
});

After doing so the DrizzleSQLiteAdapter does seem to work with Turso and I'm able to deploy the app with the latest @libsql/client version. As of yet I haven't encountered an error as I did earlier, but I'll need to do more testing to be sure as they didn't always pop-up earlier either.

Judging by this quick implementation the sessionTable dataType mismatch might be a bug in the DrizzleSQLiteAdapter, though I think this might be an issue regardless of whether LibSQL or SQLite is used. I'm guessing the adapter assumes regular SQLite functionality, whereas Drizzle offers a "date" type layered on top of it. We can work around this, but it could be confusing for people who aren't aware of it.

I'll report back when I know more. Thanks for looking into this and also in general for your open source contributions. I'm definitely looking forward for some Copenhagen reading.

from lucia.

pilcrowOnPaper avatar pilcrowOnPaper commented on September 28, 2024

Gonna close this for now, but feel free to open another issue if you find any 👍

from lucia.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.