sandros94 / nuxt-surrealdb

A Nuxt module aimed to simplify the use of SurrealDB.
https://nuxt-surrealdb.s94.dev/
MIT License
27 stars 2 forks source link

WS signin not working #19

Open EtienneBruines opened 1 week ago

EtienneBruines commented 1 week ago

Workflow:

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 commented 1 week ago

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 🙏

EtienneBruines commented 1 week ago

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

sandros94 commented 1 week ago

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...