route /login managed through vue router
This commit is contained in:
parent
5b3549068b
commit
de52c5e6be
4 changed files with 41 additions and 32 deletions
|
|
@ -1,9 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return function ($page, $kirby, $site) {
|
return function ($page, $kirby, $site) {
|
||||||
if (!$kirby->user() && $page->uri() != 'login') {
|
|
||||||
go('/login');
|
|
||||||
} else {
|
|
||||||
$data = $page->toArray();
|
$data = $page->toArray();
|
||||||
$data['template'] = (string) $page->template();
|
$data['template'] = (string) $page->template();
|
||||||
$data['newInspirations'] = (bool) page('inspirations')->children()->findBy('new', 'true');
|
$data['newInspirations'] = (bool) page('inspirations')->children()->findBy('new', 'true');
|
||||||
|
|
@ -27,5 +24,4 @@ return function ($page, $kirby, $site) {
|
||||||
'genericData' => $data,
|
'genericData' => $data,
|
||||||
'userData' => $userData ?? null
|
'userData' => $userData ?? null
|
||||||
];
|
];
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
@ -1,7 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
if (!$kirby->user()) {
|
||||||
|
return json_encode([
|
||||||
|
'page' => $genericData,
|
||||||
|
'user' => []
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
function getProjectData($project)
|
function getProjectData($project)
|
||||||
{
|
{
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'title' => $project->title()->value(),
|
'title' => $project->title()->value(),
|
||||||
'url' => $project->url(),
|
'url' => $project->url(),
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
import { createWebHistory, createRouter } from "vue-router";
|
import { createWebHistory, createRouter } from 'vue-router';
|
||||||
import routes from "./routes";
|
import routes from './routes';
|
||||||
import { useApiStore } from "../stores/api";
|
import { useApiStore } from '../stores/api';
|
||||||
import { usePageStore } from "../stores/page";
|
import { usePageStore } from '../stores/page';
|
||||||
import { useUserStore } from "../stores/user";
|
import { useUserStore } from '../stores/user';
|
||||||
import { getActivePinia } from "pinia";
|
import { getActivePinia } from 'pinia';
|
||||||
|
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
history: createWebHistory(),
|
history: createWebHistory(),
|
||||||
|
|
@ -12,10 +12,14 @@ const router = createRouter({
|
||||||
|
|
||||||
router.beforeEach(async (to, from, next) => {
|
router.beforeEach(async (to, from, next) => {
|
||||||
const pinia = getActivePinia();
|
const pinia = getActivePinia();
|
||||||
const api = useApiStore(pinia);
|
|
||||||
const pageStore = usePageStore(pinia);
|
const pageStore = usePageStore(pinia);
|
||||||
const userStore = useUserStore(pinia);
|
const userStore = useUserStore(pinia);
|
||||||
|
|
||||||
|
if (to.path === '/login') next();
|
||||||
|
|
||||||
|
if (!userStore.user) next('/login');
|
||||||
|
|
||||||
|
const api = useApiStore(pinia);
|
||||||
try {
|
try {
|
||||||
const res = await api.fetchData(to.path);
|
const res = await api.fetchData(to.path);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ const routes = [
|
||||||
component: Home,
|
component: Home,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: 'Login',
|
||||||
path: '/login',
|
path: '/login',
|
||||||
component: Login,
|
component: Login,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue