-
Hello @sandros94 , Because the documentation is missing the information on how to get the authenticated user info (or the info method is broken) I tried the following: // ./server/api/auth.ts
export default defineEventHandler(async (event) => {
const data = {
NS: config.SURREALDB_NAMESPACE,
DB: config.SURREALDB_DATABASE,
SC: config.SURREALDB_SCOPE,
email: '[email protected]',
password: 'secret'
}
// the signup method works fine !
const sessionToken = await useSurrealRPC(event, { method: 'signin', params: [data] })
console.log(sessionToken) // <- returns the token
// the info method does not work !!!
const result = await useSurrealRPC(event, { method: 'info' })
console.log(result) // <- returns null
// I've also tried this, but it's not working on the server side !
// const { info } = useSurrealDB()
// const result = await info()
return result
}) So how can I get the user information after the signin? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @dodanex Any methods that do require user's authentication are mainly for client-side usage, since SurrealDB can handle them. It is not working because you need to pass the - const result = await useSurrealRPC(event, { method: 'info' })
+ const result = await useSurrealRPC(event,
+ { method: 'info' },
+ {
+ database: {
+ NS: config.SURREALDB_NAMESPACE,
+ DB: config.SURREALDB_DATABASE,
+ SC: config.SURREALDB_SCOPE,
+ },
+ token: sessionToken,
+ },
+ )
console.log(result)
Thanks for pointing this out. I should investigate server-side operations a bit more, in particular authenticated operations. P.S.:
This isn't working because the |
Beta Was this translation helpful? Give feedback.
Hi @dodanex
first off, sorry if I still haven't created official docs. I'm working on it tho 🙏
Any methods that do require user's authentication are mainly for client-side usage, since SurrealDB can handle them.
But this server-side only use case is something I need to simplify, since it is already usable but not as simple as I would like it to be.
It is not working because you need to pass the
sessionToken
to the nextuseSurrealRPC
call