Skip to content

Commit

Permalink
fix(useSurrealAuth): stronger types
Browse files Browse the repository at this point in the history
  • Loading branch information
sandros94 committed Jun 2, 2024
1 parent 41e6b1a commit 5287dcc
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/runtime/composables/surreal-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function useSurrealAuth() {

async function getSessionExp(authToken?: string) {
const _token = authToken || token.value
return await $sql('SELECT exp FROM $session;', { database: authDatabase, token: `Bearer ${_token}` })
return await $sql<[{ result: [{ exp: number | 'NONE' | null }] }]>('SELECT exp FROM $session;', { database: authDatabase, token: `Bearer ${_token}` })
}

// info
Expand Down Expand Up @@ -82,7 +82,7 @@ export function useSurrealAuth() {
}, { database: authDatabase, token: false })
if (result) {
await getSessionExp(result).then(async ({ result: query }) => {
if (typeof query[0].result[0].exp === 'number') {
if (query && typeof query[0].result[0].exp === 'number') {
setToken(query[0].result[0].exp).value = result
await refreshInfo(result)
}
Expand Down Expand Up @@ -110,6 +110,7 @@ export function useSurrealAuth() {
..._credentials,
}, { database: authDatabase, token: false }).then(async ({ result }) => {
await getSessionExp(result).then(async ({ result: query }) => {
if (!query || typeof query[0].result[0].exp !== 'number') throw createError({ statusCode: 500, message: 'Failed to create session' })
setToken(query[0].result[0].exp).value = result
await refreshInfo(result)
})
Expand Down

0 comments on commit 5287dcc

Please sign in to comment.