#29 refactor: replace admin code with role-based auth using Pinia
This commit is contained in:
@@ -79,9 +79,14 @@
|
||||
<script>
|
||||
import trytonIcon from '../assets/icons/tryton-icon.svg';
|
||||
import AuthService from '@/services/auth';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import { inject } from 'vue';
|
||||
export default {
|
||||
name: 'NavBar',
|
||||
setup() {
|
||||
const authStore = useAuthStore();
|
||||
return { authStore };
|
||||
},
|
||||
data: () => ({
|
||||
drawer: false,
|
||||
group: null,
|
||||
@@ -129,13 +134,14 @@
|
||||
checkAuth() {
|
||||
this.isAuthenticated = AuthService.isAuthenticated();
|
||||
},
|
||||
async fetchUser() {
|
||||
try {
|
||||
this.user = await this.api.getCurrentUser();
|
||||
} catch (error) {
|
||||
console.error('Error fetching user:', error);
|
||||
}
|
||||
},
|
||||
async fetchUser() {
|
||||
try {
|
||||
this.user = await this.api.getCurrentUser();
|
||||
this.authStore.setUser(this.user);
|
||||
} catch (error) {
|
||||
console.error('Error fetching user:', error);
|
||||
}
|
||||
},
|
||||
navigate(route) {
|
||||
this.$router.push(route);
|
||||
},
|
||||
@@ -146,10 +152,11 @@
|
||||
toggleAdminMenu() {
|
||||
this.showAdminMenu = !this.showAdminMenu;
|
||||
},
|
||||
logout() {
|
||||
logout() {
|
||||
AuthService.logout();
|
||||
this.isAuthenticated = false;
|
||||
this.user = null;
|
||||
this.authStore.clearUser();
|
||||
this.$router.push('/');
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user