Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WS signin not working #19

Open
EtienneBruines opened this issue Oct 10, 2024 · 3 comments
Open

WS signin not working #19

EtienneBruines opened this issue Oct 10, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@EtienneBruines
Copy link

EtienneBruines commented Oct 10, 2024

Workflow:

  • Load the page
  • Sign in (login form or something), which calls the handler:
const { signin } = useSurrealWS() 
const result = await signin({ /* auth data */})
console.trace(result) // returns false, even though it should return a token.

Currently, the isReady.auth value in surreal-ws.js stays at false because a successful signin is never parsed (since id=1 is hardcoded and id=1 is never used to send the signin request).

This causes all queries (including signin) to return false. It does run the _init() function every time, but the _init() function does not correctly login either. It sends a potential userToken (from useSurrealAuth) or an options.auth - but never does it use anything related to the signin function.

Perhaps it makes sense to overwrite the authId when sending the signin request, or use the authId when sending the signin request instead of the auto-incremented message id?

This does not seem to be version-related, but for sake of completness:
SurrealDB version v2.0.4 and nuxt-surrealdb version v0.3.4

@sandros94
Copy link
Owner

Not only this, but also I just realized I've been using the wrong methods (making me wander why my own project with SurrealDB 1.5.4 is even working).

This requires quite some work compared to the other issue, thanks for reporting it 🙏

@sandros94 sandros94 self-assigned this Oct 10, 2024
@sandros94 sandros94 added the bug Something isn't working label Oct 10, 2024
@EtienneBruines
Copy link
Author

That might explain the generated surreal-ws.d.ts file saying that (almost) all functions return boolean and not boolean | any.

@sandros94
Copy link
Owner

That might explain the generated surreal-ws.d.ts file saying that (almost) all functions return boolean and not boolean | any.

Oh, about this: no they are supposed to only return booleans. If you need to access the actual information you have to access data to do so.

In the your provided snipped you should do something like (although, still not ideal):

const { data, signin } = useSurrealWS() 
const result = await signin({ /* auth data */})
if (result) {
  console.trace(data.value)
}

This is one of the reasons why I suggest to use signin operations outside/before creating a ws connection.

data will update whenever SurrealDB has to inform you about something you have executed or subscribed at (like with a live('table_name')), but I currently don't inform which id is about which data return.

I can already see me rewrite useSurrealWS from scratch...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants