Replies: 2 comments 1 reply
-
|
Hi @hgoona ! Thanks for bringing this up. To be honest, I’m surprised it took this long for someone to ask this, as it's a crucial part of building scalable apps. ClarificationsThis adapter is designed to be highly adaptable to various scenarios and environments. However, it is intentionally a thin layer that translates The Path to a SolutionSince the adapter doesn't manage the connection, it cannot provide the "authenticated connection" out of the box, but it is built to work perfectly in such a scenario. You just need a few extra steps to bridge the two. There are several ways to achieve this, but the most robust one (which I recommend) involves using JWTs and JWKS. To trigger SurrealDB's built-in RLS, you need a JWT token that SurrealDB trusts. You can issue this token via The Setup Pattern1. On the Better-Auth side:
2. On the SurrealDB side:
Once this is set up, when a user logs in, they get a JWT. You can then use this token to authenticate your SurrealDB client ( Pro-Tips for ArchitectureI highly recommend the following structure for production apps:
Why this architecture?
I don't have the capacity to create a full interactive example right now, but I would highly welcome any contributions to the documentation or examples folder regarding this pattern! Note On a side note, I have recently stabilized a new version of the adapter that supports SurrealDB v3+, SurrealDB SDK JS v2+, and the latest Better-Auth 1.5+. This version was rebuilt from scratch (leveraging only small parts of the original code) and includes several key optimizations that make it significantly better than v1. While it still requires intensive testing before being officially labeled as "stable," I highly recommend using this version if you have the flexibility to experiment with it. It’s in a much better position architecturally than the previous release.
I would be extremely grateful for any feedback, bug reports, or suggestions regarding this beta version! |
Beta Was this translation helpful? Give feedback.
-
|
Hi @oskar-gmerek this sounds like an AI reply and doesn't seem correct. Do you mind reviewing? / clarifying? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi @oskar-gmerek , great adaptor!
I'm trying to get my head around the way better-auth likes to do things and I'm wondering if I've missed something:
When the user goes through the sign in process and has entered the secured part of the app, is there a surreal db connection authenticated with the user's credential, that the user can therefore use to make queries with?
Previously I had setup auth without better-auth and of sign up user with root permission db connection (server side only) , then sign in with a db instance that retains the user credentials - so that their queries follow the rbac policy setup on each table etc.
Is something like this available via this adaptor, or is it done in a different way? Would be grateful for a minimum example, eg. how a signed in user can securely do a form action query to surrealdb?
NOTE: I've already successfully got the base setup of better-auth and this adaptor fully working. Just unsure about the above pattern for db querying.
Beta Was this translation helpful? Give feedback.
All reactions