#29 refactor: replace admin code with role-based auth using Pinia
This commit is contained in:
@@ -1,51 +0,0 @@
|
||||
<template>
|
||||
<v-dialog v-model="dialog" persistent>
|
||||
<v-card>
|
||||
<v-card-title>
|
||||
Ingrese el código
|
||||
</v-card-title>
|
||||
<v-card-text>
|
||||
<v-form id="code-form" @submit.prevent="verifyCode">
|
||||
<v-text-field v-model="code" label="Código" type="password" autocomplete="off" />
|
||||
</v-form>
|
||||
</v-card-text>
|
||||
<v-card-actions>
|
||||
<v-btn type="submit" form="code-form" color="green">Aceptar</v-btn>
|
||||
<v-btn :to="{ path: '/' }" color="red">Cancelar</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</v-dialog>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { inject } from 'vue';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
api: inject('api'),
|
||||
dialog: true,
|
||||
code: '',
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
verifyCode() {
|
||||
this.api.isValidAdminCode(this.code)
|
||||
.then(data => {
|
||||
if (data['validCode']) {
|
||||
this.$emit('code-verified', true);
|
||||
this.dialog = false;
|
||||
} else {
|
||||
alert('Código incorrecto');
|
||||
this.$emit('code-verified', false);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
alert('Error al validar el código');
|
||||
this.$emit('code-verified', false);
|
||||
console.error(error);
|
||||
});
|
||||
}
|
||||
},
|
||||
}
|
||||
</script>
|
||||
@@ -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