added error handling and cleaned up styles

This commit is contained in:
Edward Tirado Jr 2026-04-10 18:10:01 -05:00
parent 21c3d42d90
commit 93c60498d0
6 changed files with 137 additions and 33 deletions

View file

@ -6,7 +6,16 @@ export const useAuth = () => {
baseURL: config.public.apiBase,
credentials: 'include',
})
await $api('/api/login', {method: 'POST', body: {email, password}})
await $api('/api/login', {
method: 'POST',
onResponseError({response}) {
if (response.status === 401) {
throw new Error('INVALID_CREDENTIALS')
}
},
body: {email, password}
}
)
window.location.href = '/lists'
}
@ -15,7 +24,16 @@ export const useAuth = () => {
baseURL: config.public.apiBase,
credentials: 'include',
})
await $api('/api/register', {method: 'POST', body: {email, username}})
await $api('/api/register', {
method: 'POST',
onResponseError({response}) {
console.log("wat", response)
if (response.status === 422) {
throw new Error(response._data.message)
}
},
body: {email, username}
})
await navigateTo('/auth/login')
}