Initial commit: Vuelato - buscador de vuelos
Some checks failed
ci / ci (22, ubuntu-latest) (push) Has been cancelled
Some checks failed
ci / ci (22, ubuntu-latest) (push) Has been cancelled
Nuxt 4 + Supabase + Flightics API. Incluye búsqueda de vuelos, inspiraciones, watchlist, tracking de precios y mapa interactivo. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
43
app/composables/useAuth.ts
Normal file
43
app/composables/useAuth.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
export function useAuth() {
|
||||
const supabase = useSupabaseClient()
|
||||
const user = useSupabaseUser()
|
||||
|
||||
const loading = ref(false)
|
||||
const error = ref<string | null>(null)
|
||||
|
||||
async function login(email: string, password: string) {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
const { error: err } = await supabase.auth.signInWithPassword({ email, password })
|
||||
if (err) error.value = err.message
|
||||
loading.value = false
|
||||
return !err
|
||||
}
|
||||
|
||||
async function register(email: string, password: string) {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
const { error: err } = await supabase.auth.signUp({ email, password })
|
||||
if (err) error.value = err.message
|
||||
loading.value = false
|
||||
return !err
|
||||
}
|
||||
|
||||
async function loginWithGoogle() {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
const { error: err } = await supabase.auth.signInWithOAuth({
|
||||
provider: 'google',
|
||||
options: { redirectTo: `${window.location.origin}/auth/confirm` }
|
||||
})
|
||||
if (err) error.value = err.message
|
||||
loading.value = false
|
||||
}
|
||||
|
||||
async function logout() {
|
||||
await supabase.auth.signOut()
|
||||
await navigateTo('/')
|
||||
}
|
||||
|
||||
return { user, loading, error, login, register, loginWithGoogle, logout }
|
||||
}
|
||||
Reference in New Issue
Block a user