Wrap await in try/catch to fix sign-in in tauri builds (#349)

Fixes #342
This commit is contained in:
Pierre Jacquier
2023-08-29 21:45:40 -04:00
committed by GitHub
parent 853389ba22
commit 2b1a556b81

View File

@ -98,12 +98,16 @@ async function getUser(context: UserContext) {
} }
if (!context.token && '__TAURI__' in window) throw 'not log in' if (!context.token && '__TAURI__' in window) throw 'not log in'
if (context.token) headers['Authorization'] = `Bearer ${context.token}` if (context.token) headers['Authorization'] = `Bearer ${context.token}`
const response = await fetch(url, { try {
method: 'GET', const response = await fetch(url, {
credentials: 'include', method: 'GET',
headers, credentials: 'include',
}) headers,
const user = await response.json() })
if ('error_code' in user) throw new Error(user.message) const user = await response.json()
return user if ('error_code' in user) throw new Error(user.message)
return user
} catch (e) {
console.error(e)
}
} }