movie-night-web/app/composables/useAuth.ts

20 lines
545 B
TypeScript
Raw Normal View History

2026-02-24 00:20:54 -06:00
export const useAuth = () => {
const config = useRuntimeConfig()
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 navigateTo('/')
2026-02-24 00:20:54 -06:00
}
const logout = async () => {
await $api('/api/logout', {method: 'POST'})
await navigateTo('/auth/login')
2026-02-24 00:20:54 -06:00
}
return {login, logout}
}