RFC: Lucia v3 #1253
Replies: 14 comments 26 replies
-
I mean no disrespect with what I am about to say, but I genuinely believe this is the wrong direction to go. Rule number 1 of authentication, don't roll your own auth and that is exactly what Lucia V3 is going to force everyone to do. When you force users of your library to handle checking and hashing passwords you can recommend Argon2id all day long, but somebody out there is going to use MD5. Moreover, yes the keys system is limiting and complex, but it's way less complex than trying to manage and link profiles on your own. Auth0 faced a similar problem, and they struggled with it for a long time. Eventually though, people got used to how it works and just rolled with it. However, I will concede that using the actual 1st party libraries for OAuth is probably a smart idea, but it's not a one size fits all solution. There are cases where having an OAuth library that is tailored to your authorization library makes perfect sense. This is one of those cases in my opinion. Ultimately, I will keep an eye on this RFC, and the decision ultimately lies with the team behind Lucia; but if this is the direction Lucia intends to go, I'll just migrate all of my projects to Supabase Auth. |
Beta Was this translation helpful? Give feedback.
-
Sorry if it's the wrong place to ask, but with |
Beta Was this translation helpful? Give feedback.
-
As someone who has followed you on Twitter for a while now I'm a bit disappointed to hear this. I know absolutely nothing about Auth, I want an Auth library with ALL the opinions from someone who understands it completely. I want to not think about anything. Auth is very complex, I assumed Lucia was this library as on Twitter you have lots of great tweets on the topic. It sounds like you're moving away from something that has opinions I would want to something that wants my opinions. My opinions suck. |
Beta Was this translation helpful? Give feedback.
-
I very much agree with this part, as I am having trouble implementing with the current Key concept. |
Beta Was this translation helpful? Give feedback.
-
After reading some peoples' responses here, I realize Lucia always stood in a weird place because it started out as a Session management library, but sort of evolved into an easy to use and easy to get started auth library. Auth libraries are hard because, they are never going to compete with a fully fledged service such as Clerk, or Auth0, or even Supabase Auth, as they have complete control over everything and just give you a modal. But that's okay! You will have a few groups of people...
Unfortunately, you can't please everyone as everyones needs are different. But I can definitely say drastic changes are gonna make a lot of people nervous |
Beta Was this translation helpful? Give feedback.
-
How limiting is oslo in regards to when ran on node vs bun runtimes? |
Beta Was this translation helpful? Give feedback.
-
I hope there would be complete guides for OAuth implementations for various models i.e PKCE. I switched to lucia specifically for OAuth handling and so I am starting to wonder if this was the right choice as I am not trying to create my entire own oauth system. It seems like Lucia v3 will be primitives to create oauth but I still have to put in the work to make things run. |
Beta Was this translation helpful? Give feedback.
-
To respond to a specific aspect: Regarding naming, you could consider putting session-related items onto a session.create(sessionId: string, attributes: DatabaseSessionAttributes)
session.get(sessionId: string)
session.getAll(userId: string)
session.invalidate(sessionId: string)
session.invalidateAll(userId: string)
session.readCookie(sessionId: string)
session.createCookie(sessionId: string)
... Similarly, it'd be be nice to see naming where the user's id within the user's object is simply const user = {
id: 'abc123'
} not like this: const user = {
userId: 'abc123'
} because it's redundant when used (e.g. Same for |
Beta Was this translation helpful? Give feedback.
-
I will add that I think having a separate package named These methods could just as easily be exported from Lucia. |
Beta Was this translation helpful? Give feedback.
-
In lucia v2, it is not easy to swap out scrypt... so this v3 proposal is great to make that more modular. It would be nice if a recommended solution could be provided for non-legacy hashing in a cloudflare worker environment. I tested https://github.com/auth70/argon2-wasi and it works. hash-wasm would probably also work but needs a build step to create wasm binaries. Daninet/hash-wasm#56 Maybe there could be an oslo/password-wasm package. If it's too much to maintain in oslo, a guide for one of these other webassembly solutions would work. Thanks! |
Beta Was this translation helpful? Give feedback.
-
From what I've read/seen, I'm gathering that the folks who are against this change in direction to just session handling are mainly the folks that currently rely on Lucia's authentication implementation because they don't know how to do it themselves safely and securely. I think the change will be less stressful to those folks if meaningful documentation and guides are provided (like in the nicely written guidebooks https://lucia-auth.com/guidebook/) that could show them a good example implementation of the user authentication (securely and properly) alongside with the new library. That way some people don't feel totally lost since they have a starting point to go off of for secure authentication, and that also may help current Lucia users who try to switch not compromise their user data through a poor attempt that results insecure implementation. If Oslo will handle this already then great! |
Beta Was this translation helpful? Give feedback.
-
Ok, after testing the beta version (see #1258), I'm happy with the general direction of the proposal. As such, I am going forward with this change. Thanks to everyone who left a comment in the discussion. The details are still being fleshed out and specific APIs might change. I'll announce it on Twitter and Discord when we've built the basic documentation. In the meantime, if you want to play around, you can install the beta version with |
Beta Was this translation helpful? Give feedback.
-
Based on the relatively positive feedback on #1231, I thought I'd write a more comprehensive proposal.
You can find the work-in-progress source code in the
v3
branch.Redefining Lucia
Lucia will handle sessions and related database queries. That's it. It will no longer handle the authentication step (OAuth and password check) and users. For an in depth explanation, see #1231. However, in short, the database adapter model and keys are too limiting for handling various auth methods, especially as each project has different requirements. Removing keys allow simple projects to use a more simple model, and complex projects to not worry about limitations set by Lucia. I also think there's more value for Lucia to focus on the docs than to provide wrappers around database queries.
There will be an even more heavy focus on the docs. While we are removing APIs for checking passwords etc, there will be proper guides on implementing OAuth, email/password, passkeys, and more.
Oslo
Lucia will be built on
oslo
. It provides APIs for:Guides for OTP, custom OAuth providers, passkeys, etc will use Oslo.
New API
Lucia will be initialized with
Lucia()
instead of a functionlucia()
. See Embracing classes for details.Here's the entire core API:
That's it. No more extra bloat that you can just use your ORM/query-builder for. I'm still considering whether to add an
updateSessionAttributes()
however.AuthRequest
will be mostly the same, except forAuthRequest.setSession()
, which will be replaced byAuthRequest.setSessionCookie()
andAuthRequest.deleteSessionCookie()
.Updated configuration
getSessionAttributes()
andgetUserAttributes()
will only be providedDatabaseSessionAttributes
andDatabaseUserAttributes
I have removed the
env
config. I have moved it tosessionCookie.attributes.secure
to make the relation more clear.Error handling
v3 will no longer throw errors and thus
LuciaError
is removed. This is huge in terms of usability and maintainability. That said, all APIs will still throw a database error (connection error, etc).Embracing classes
lucia()
will be changed tonew Lucia()
,prisma()
adapter tonew PrismaAdapter()
, etc. This change will make extending existing adapters much easier:Type declarations
You no longer have to declare types with
.d.ts
.Hashing passwords
While we recommend using Argon2id for new projects, for older projects you can use
generateLegacyLuciaPasswordHash()
andverifyLegacyLuciaPasswordHash()
to hash passwords.Deprecating
@lucia-auth/oauth
Since we're removing keys, there's no way to provide an OAuth integration specifically for Lucia. However,
@lucia-auth/oauth
still provides a lot of value by handling all the API requests. So, I'll be extracting part of it into a new package (currently work-in-progress). This package is also built on Oslo. I will make sure it'll have all providers currently provided by@lucia-auth/oauth
by the release. This package will also include some improvements over the existing OAuth integration, namely better errors and an API for refreshing access tokens.Database
Database schema
As always, you can add custom columns to both the user and session table. The session table will not support default values.
user
tableid
string
session
tableexpires_at
will replaceactive_expires
andidle_expires
.id
string
user_id
string
expires_at
Date
Adapter API
The adapter API is significantly simplified. Adapters no longer have to worry about errors as well. This means adapters for ORMs and query builders are now possible.
Session adapters
There's a bit more work to get session adapters working since you can no longer merge it with a regular adapter.
Beta Was this translation helpful? Give feedback.
All reactions