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