Implement Smart Location: auto-detect user location if preference is enabled, hide location button, and handle permission denial by resetting preference
This commit is contained in:
@ -51,7 +51,7 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
}
|
||||
}
|
||||
|
||||
async function register(email: string, pass: string, fullName: string) {
|
||||
async function register(email: string, pass: string, fullName: string, autoLocation: boolean = false) {
|
||||
console.log('Realizando signUp en Supabase...')
|
||||
const { data, error } = await supabase.auth.signUp({
|
||||
email,
|
||||
@ -59,7 +59,8 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
options: {
|
||||
data: {
|
||||
full_name: fullName,
|
||||
role: 'PASSENGER'
|
||||
role: 'PASSENGER',
|
||||
auto_location: autoLocation
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -100,6 +101,21 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
window.location.replace('/login')
|
||||
}
|
||||
|
||||
async function updateProfile(updates: any) {
|
||||
if (!userSession.value?.user?.id) return
|
||||
|
||||
const { error } = await supabase
|
||||
.from('users')
|
||||
.update(updates)
|
||||
.eq('id', userSession.value.user.id)
|
||||
|
||||
if (!error) {
|
||||
userProfile.value = { ...userProfile.value, ...updates }
|
||||
} else {
|
||||
console.error('SIBU | Error al actualizar perfil:', error)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
userSession,
|
||||
userProfile,
|
||||
@ -112,6 +128,7 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
isPassenger,
|
||||
login,
|
||||
register,
|
||||
logout
|
||||
logout,
|
||||
updateProfile
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user