#29 refactor: replace admin code with role-based auth using Pinia

This commit is contained in:
mono
2026-03-14 22:55:24 -05:00
parent 2c9ea4b871
commit 786d0551bb
12 changed files with 105 additions and 129 deletions

View File

@@ -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('/');
},
}