Rust-based Auth
Out of interest. Seeing convex is rust based. Why wasn't there a native rust implementation of auth? ๐ค I suppose the choice to go with auth.js is that there are more important things to do first?
11 Replies
On the backend auth (validating the JWT, etc.) is implemented in Rust. But for an auth library, ecosystem compatibility and programability are the top priorities.
@Paul what aspects of auth might you expect to be implemented in Rust? Are you talking about the Convex Auth library?
Today in Convex developers write their applications, frontend and Convex backend functions, in TypeScript. Someday we'd like to see folks writing backend functions in Rust, but we haven't prioritized a Rust SDK for writing Convex functions because the power of using the same language on the frontend and the backend is so great.
On the backend auth (validating the JWT, etc.) is implemented in Rust. But for an auth library, ecosystem compatibility and programability are the top priorities.I didn't know that! I haven't yet gone through the code and assumed that due to auth.js being used. That's where the emphasis for the question was.
what aspects of auth might you expect to be implemented in Rust?creation, query and management of the JWT and refresh via the js SDK.
Rust SDKI'm not advocating for developing in rust. I have actually thought (deeply) about this, since I have a heavy rust backend. It's always just easier to do things in javascript. ๐ It's probably due to having a much stronger dev exp with it, rather than in rust. Something I will fix this year though. ๐ Looks like I'm going to have to put on my list, pulling apart convex and going through the code.
Happy to answer questions too! Especially interested in what feels like it's missing from the SDK surface, and we can decide internally whether to implement things in Rust vs JS. But if it's userspace code, code that's just a library running on your Convex deployment, today that has to be JS.
Yeah when you run your own JWT minting by implementing OAuth yourself with the Convex Auth library (the thing that uses parts of auth.js) that's all done in JS on your deployment. It's just user-space code that some people run on their deployments.
It's always just easier to do things in javascript. ๐ It's probably due to having a much stronger dev exp with it, rather than in rust.It's real, Rust is pretty great language for building a database but very few would cite it as a favorite for business logic
creation, query and management of the JWT and refresh via the js SDKThat makes sense, yeah if being an OAuth identity provider every becomes part of the core product we could do this. Today this is all userspace stuff though, it's just some JavaScript you're running on your database.
Just to confirm, this is where all the JWT stuff happens on the backend?
https://github.com/get-convex/convex-backend/tree/main/crates/authentication
GitHub
convex-backend/crates/authentication at main ยท get-convex/convex-ba...
The Convex open-source backend. Contribute to get-convex/convex-backend development by creating an account on GitHub.
Yeah, here the backend just validates the identity send in on the websocket or HTTP request. https://github.com/get-convex/convex-backend/blob/main/crates/authentication/src/lib.rs in particular
@Paul All the backend does is validate and expose these to the JS layer of queries, mutations and actions via
ctx.auth.getUserIdentity()
These JWTs can be provided by any OpenID Connect-compliant identity provider, we point people to Clerk or Auth0. The browser goes through that auth flow and then handles keeping the identity up to date by refreshing those tokens over time. If you want to use your Convex backend instead of Clerk, we have an npm library that implements that OpenID Connect identity token flow on the Convex deployment (aka backend) and relevant client code to talk to it.we have an npm libraryIs that the lib that's based on auth.js?
Yeah, https://labs.convex.dev/auth https://github.com/get-convex/convex-auth
it uses parts of auth.js as a dependency https://github.com/get-convex/convex-auth/blob/main/package.json#L76
Also a few pilcrowonpaper libs I see as well. ๐
yeah his work has been really helpful!
It's a shame lucia was deprecated. Definitely really liked his work.
I think I have what I need to start taking a look. So much appreciative! Although it won't be for a week or so. About to go down another different rabbit hole.
So thanks again!
Good luck on your other rabbit hole! Would love to hear how you find it when you get back to Convex. Then later if you dive into the Rust stuff, we're working on our open source flows atm, either for debugging or contributions the codebase should be easier to interact with soon.