diff --git a/src/components/NavBar.vue b/src/components/NavBar.vue
index 0f2f5ef..63169fe 100644
--- a/src/components/NavBar.vue
+++ b/src/components/NavBar.vue
@@ -13,11 +13,37 @@
- Logout
+
+
+
+ {{ user?.username }}
+ {{ user?.email }}
+
+
+
+ {{ user?.first_name }} {{ user?.last_name }}
+
+
+
+ {{ user?.is_staff ? 'Administrador' : 'Usuario' }}
+
+
+
+
+
+ mdi-logout
+ Cerrar sesión
+
+
+
+
+ mdi-account
+ {{ user?.username }}
import trytonIcon from '../assets/icons/tryton-icon.svg';
import AuthService from '@/services/auth';
+ import { inject } from 'vue';
export default {
name: 'NavBar',
data: () => ({
@@ -60,6 +87,8 @@
group: null,
showAdminMenu: false,
isAuthenticated: false,
+ user: null,
+ api: inject('api'),
menuItems: [
{ title: 'Inicio', route: '/', icon: 'mdi-home'},
{ title: 'Comprar', route:'/comprar', icon: 'mdi-cart'},
@@ -76,6 +105,9 @@
}),
mounted() {
this.checkAuth();
+ if (this.isAuthenticated) {
+ this.fetchUser();
+ }
},
watch: {
group () {
@@ -89,6 +121,13 @@
checkAuth() {
this.isAuthenticated = AuthService.isAuthenticated();
},
+ async fetchUser() {
+ try {
+ this.user = await this.api.getCurrentUser();
+ } catch (error) {
+ console.error('Error fetching user:', error);
+ }
+ },
navigate(route) {
this.$router.push(route);
},
@@ -99,11 +138,12 @@
toggleAdminMenu() {
this.showAdminMenu = !this.showAdminMenu;
},
- logout() {
- AuthService.logout();
- this.isAuthenticated = false;
- this.$router.push('/');
- },
+ logout() {
+ AuthService.logout();
+ this.isAuthenticated = false;
+ this.user = null;
+ this.$router.push('/');
+ },
}
}
diff --git a/src/services/api.js b/src/services/api.js
index 1bc6b51..d683e15 100644
--- a/src/services/api.js
+++ b/src/services/api.js
@@ -62,6 +62,10 @@ class Api {
sendSalesToTryton(){
return this.apiImplementation.sendSalesToTryton();
}
+
+ getCurrentUser() {
+ return this.apiImplementation.getCurrentUser();
+ }
}
export default Api;
diff --git a/src/services/django-api.js b/src/services/django-api.js
index b302065..5fc4bb3 100644
--- a/src/services/django-api.js
+++ b/src/services/django-api.js
@@ -88,6 +88,11 @@ class DjangoApi {
const url = this.base + '/don_confiao/api/enviar_ventas_a_tryton';
return this.postRequest(url, {});
}
+
+ getCurrentUser() {
+ const url = this.base + '/users/me/';
+ return this.getRequest(url);
+ }
}
export default DjangoApi;