fix user login page display
This commit is contained in:
parent
de52c5e6be
commit
009752ff32
3 changed files with 15 additions and 8 deletions
|
|
@ -1,7 +1,7 @@
|
|||
<template>
|
||||
<h1 v-if="page" class="sr-only">{{ page.content.title }}</h1>
|
||||
<div :class="{ 'with-sidebar': page?.template !== 'login' }">
|
||||
<Menu v-if="page?.template !== 'login'" />
|
||||
<Menu v-if="isLogged" />
|
||||
<RouterView />
|
||||
</div>
|
||||
</template>
|
||||
|
|
@ -11,6 +11,7 @@ import { storeToRefs } from 'pinia';
|
|||
import Menu from './components/Menu.vue';
|
||||
import { usePageStore } from './stores/page';
|
||||
import { detect } from 'detect-browser';
|
||||
import { useUserStore } from './stores/user';
|
||||
|
||||
const browser = detect();
|
||||
|
||||
|
|
@ -20,4 +21,5 @@ if (browser) {
|
|||
).dataset.browser = `${browser.name} ${browser.version} ${browser.os}`;
|
||||
}
|
||||
const { page } = storeToRefs(usePageStore());
|
||||
const { isLogged } = storeToRefs(useUserStore());
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -17,12 +17,12 @@ router.beforeEach(async (to, from, next) => {
|
|||
|
||||
if (to.path === '/login') next();
|
||||
|
||||
if (!userStore.user) next('/login');
|
||||
|
||||
const api = useApiStore(pinia);
|
||||
try {
|
||||
const res = await api.fetchData(to.path);
|
||||
|
||||
if (!res.user) next('/login');
|
||||
|
||||
pageStore.page = res.page;
|
||||
userStore.user = res.user;
|
||||
next();
|
||||
|
|
|
|||
|
|
@ -1,10 +1,14 @@
|
|||
import { defineStore, storeToRefs } from "pinia";
|
||||
import { ref, computed } from "vue";
|
||||
import { useProjectsStore } from "./projects";
|
||||
import { defineStore, storeToRefs } from 'pinia';
|
||||
import { ref, computed } from 'vue';
|
||||
import { useProjectsStore } from './projects';
|
||||
|
||||
export const useUserStore = defineStore("user", () => {
|
||||
export const useUserStore = defineStore('user', () => {
|
||||
const user = ref(null);
|
||||
|
||||
const isLogged = computed(() => {
|
||||
return user.value?.hasOwnProperty('role');
|
||||
});
|
||||
|
||||
const { projects } = storeToRefs(useProjectsStore());
|
||||
|
||||
const notifications = computed(() => {
|
||||
|
|
@ -22,7 +26,7 @@ export const useUserStore = defineStore("user", () => {
|
|||
});
|
||||
|
||||
function readNotification(notificationId, projectId) {
|
||||
console.log("Read notification", notificationId, projectId);
|
||||
console.log('Read notification', notificationId, projectId);
|
||||
projects.value = projects.value.map((project) => ({
|
||||
...project,
|
||||
notifications:
|
||||
|
|
@ -57,6 +61,7 @@ export const useUserStore = defineStore("user", () => {
|
|||
|
||||
return {
|
||||
user,
|
||||
isLogged,
|
||||
notifications,
|
||||
readNotification,
|
||||
readAllNotifications,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue