Comments (8)
Okay, so purely about auth. I would honestly rather suggest just to open a new connection to validate auth and to close it afterwards. The .authenticate()
method will return true
if successful (note that the experimental HTTP client does not validate the token, the WS client does). You can optionally also use the .info()
method to select the data from the scope user's record.
Selecting should not trigger any updates, unless you are doing complex logic with futures :)
from surrealdb.js.
Hello
Can I get an opportunity to work on this issue? I'm very much interested in this project, and I'm very familiar with node.js. Thank you.
from surrealdb.js.
@woodmark-dev yes, please feel free to take this up if you're interested in it. We'd be glad to help out if you need any assistance! ^_^
from surrealdb.js.
Hi @LeoDog896, as for retrieving the currently authenticated user's record, we have the .info()
method. @woodmark-dev I think we track the token internally already, we can simply add a method to return that token when invoked. Feel free to open a PR for that, thanks!
from surrealdb.js.
Oh, to add @LeoDog896, the .signin()
and .signup()
methods currently already return a token for the authenticated user. The types for the .signin()
methods need to be adjusted to always return a string (the token), as root users now also get back a token. This means that you will either receive a token, or an error will be thrown 😁
from surrealdb.js.
We have the
.info()
method for retrieving the currently authenticated user's record.
Absolutely! However, that requires authenticating the current scope. Still, since I'm doing this server-side, I don't want to authenticate the server-side connection with this user scope - I would like to be able to query it without mutating the authentication state of the current connection.
EDIT: Thanks for this! I realized the original issue I made encapsulated my original problem, but what I was looking for.
Essentially, I want to do server-side sign-in/sign-up logic without duplicating the permission logic from both the server and client state.
For example, if I can have a method for signin
or signup
that returns the auth token WITHOUT authenticating the current connection, then I can use that token and see if that token has permission to run a given query, meaning that I can use SurrealDB's native permission logic without having to copy it twice to my SSR logic.
Code sample:
await db.connect('https://cloud.surrealdb.com/rpc', ...);
// normal client-side usage
await db.signin(...)
await db.query(...)
// server-side usage that doesn't mutate the current db state
const token = await db.signinOnly(...)
await db.tryQuery(token, ...)
(This feature may be crucial for SSR-powered web frameworks like Next or SvelteKit to work efficiently with SurrealDB)
By the way, since I realize I'm asking a lot, I don't mind working on this feature myself whatsoever 👍
from surrealdb.js.
Ah! So to confirm if I understand this correctly: Do you want to be able to essentially dry run queries to see how they will affect the database?
from surrealdb.js.
Not in that full scope, but essentially a dry-run signin/signup query, and the ability to use those signin/signup queries in requests. The actual (name pending) tryQuery
method itself isn't a dry run, but an authenticated request from those dry-run signin/signup queries.
*If SurrealDB supports dry runs in their database, that would probably in itself be a whole other issue.
from surrealdb.js.
Related Issues (20)
- Bug: CF Pages SSR with SurrealJS fails HOT 2
- Feature: Parse object- and array based record ID HOT 5
- Bug: Using docker compose networking causes TypeError: t.mask is not a function or connection to hang when running .wait() or .query() HOT 2
- [BUG]: Path is ignored in the Connenction URL HOT 1
- Documentation: Further define `thing` on db.create/merge/delete/select HOT 2
- Bug: Argument of type 'TemplateStringsArray' is not assignable to parameter of type 'string[]' HOT 1
- Bug: JS Sdk disconnected and couldn't authenticate again
- Bug: node_js_1.default is not a constructor at SurrealSocket.open HOT 1
- Bug: HOT 1
- Bug: Missing typing on `.query` method
- Feature: Implement toString and fromString for RecordId class HOT 1
- Feature: RecordId class should error if passing a RecordId as parameter
- Bug: Scope authentication id variable not working HOT 3
- Bug: Connection Unavailable with HTTP protocol in v1.0.0-beta.5 HOT 6
- Bug: problems in v1.0.0-beta.5 with select, delete and update functions when providing ID and inconsistency when returning JSON results from select and create functions. HOT 2
- Bug: CBORError: Remaining bytes HOT 10
- Feature: support custom fetch functions HOT 4
- Bug: WS connection does not work using node 22 HOT 3
- Bug: Type mismatch in geometries HOT 5
- Bug: create does not work with 1.0.0-beta.6 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from surrealdb.js.