feat(stores): añadido almacenamiento de datos para el registro de un usuario

parent 63a15e77
Showing with 25 additions and 0 deletions
...@@ -55,6 +55,30 @@ export const useAuthStore = defineStore('auth', { ...@@ -55,6 +55,30 @@ export const useAuthStore = defineStore('auth', {
this.isAuthenticated = true; this.isAuthenticated = true;
api.defaults.headers.common['Authorization'] = `Bearer ${token}`; api.defaults.headers.common['Authorization'] = `Bearer ${token}`;
} }
},
async register(userData) {
try {
const { token, email, role } = await authService.register(userData);
this.token = token;
this.user = { email, role };
this.isAuthenticated = true;
localStorage.setItem('jwt_token', token);
localStorage.setItem('user_email', email);
localStorage.setItem('user_role', role);
api.defaults.headers.common['Authorization'] = `Bearer ${token}`
return true;
} catch (error) {
console.error('Error al registrar cuenta:', error);
let errorMsg = 'Error';
if (error.response && error.response.data && error.response.data.message) {
errorMsg = error.response.data.message;
}
throw new Error(errorMsg);
}
} }
} }
}); });
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment