added auth support

This commit is contained in:
Edward Tirado Jr 2026-02-24 00:20:54 -06:00
parent 869be69d67
commit f3dbaef776
7 changed files with 112 additions and 3 deletions

View file

@ -0,0 +1,20 @@
export const useAuth = () => {
const config = useRuntimeConfig()
const router = useRouter()
const login = async (email: string, password: string) => {
await $fetch('/sanctum/csrf-cookie', {
baseURL: config.public.apiBase,
credentials: 'include',
})
await $api('/api/login', {method: 'POST', body: {email, password}})
await router.push('/')
}
const logout = async () => {
await $api('/api/logout', {method: 'POST'})
await router.push('/')
}
return {login, logout}
}