feature/rbac y perfiles implementados
This commit is contained in:
@@ -23,11 +23,12 @@ export default function Login() {
|
||||
const apiUrl = import.meta.env.VITE_EFC_API_URL || '';
|
||||
const token = data.access;
|
||||
try {
|
||||
const res = await fetch(`${apiUrl}/user/users/me/`, {
|
||||
headers: { 'Authorization': `Bearer ${token}` }
|
||||
});
|
||||
if (res.ok) {
|
||||
const user = await res.json();
|
||||
const [resUser, resPerms] = await Promise.all([
|
||||
fetch(`${apiUrl}/user/users/me/`, { headers: { 'Authorization': `Bearer ${token}` } }),
|
||||
fetch(`${apiUrl}/rbac/my-permissions/`, { headers: { 'Authorization': `Bearer ${token}` } }),
|
||||
]);
|
||||
if (resUser.ok) {
|
||||
const user = await resUser.json();
|
||||
if (user && user.username) {
|
||||
localStorage.setItem('username', user.username);
|
||||
if (user.email) localStorage.setItem('user_email', user.email);
|
||||
@@ -38,6 +39,12 @@ export default function Login() {
|
||||
if (typeof user.is_importador !== 'undefined') localStorage.setItem('user_is_importador', String(user.is_importador));
|
||||
}
|
||||
}
|
||||
if (resPerms.ok) {
|
||||
const permsData = await resPerms.json();
|
||||
if (permsData && permsData.permissions) {
|
||||
localStorage.setItem('user_permissions', JSON.stringify(permsData.permissions));
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// Si falla, continuar igual
|
||||
console.error('No se pudo guardar info de usuario en localStorage', e);
|
||||
|
||||
Reference in New Issue
Block a user