route /login managed through vue router

This commit is contained in:
isUnknown 2025-04-30 16:09:24 +02:00
parent 5b3549068b
commit de52c5e6be
4 changed files with 41 additions and 32 deletions

View file

@ -1,31 +1,27 @@
<?php
return function ($page, $kirby, $site) {
if (!$kirby->user() && $page->uri() != 'login') {
go('/login');
} else {
$data = $page->toArray();
$data['template'] = (string) $page->template();
$data['newInspirations'] = (bool) page('inspirations')->children()->findBy('new', 'true');
$data = $page->toArray();
$data['template'] = (string) $page->template();
$data['newInspirations'] = (bool) page('inspirations')->children()->findBy('new', 'true');
if ($kirby->user()) {
$userData = [
"role" => (string) $kirby->user()->role(),
"uuid" => (string) $kirby->user()->uuid()
];
if ($kirby->user()->client()->exists() && $kirby->user()->client()->isNotEmpty()) {
$userData['client'] = [
"name" => (string) $kirby->user()->client()->toPage()->title(),
"uuid" => (string) $kirby->user()->client()->toPage()->uuid()
];
}
}
return [
'genericData' => $data,
'userData' => $userData ?? null
if ($kirby->user()) {
$userData = [
"role" => (string) $kirby->user()->role(),
"uuid" => (string) $kirby->user()->uuid()
];
if ($kirby->user()->client()->exists() && $kirby->user()->client()->isNotEmpty()) {
$userData['client'] = [
"name" => (string) $kirby->user()->client()->toPage()->title(),
"uuid" => (string) $kirby->user()->client()->toPage()->uuid()
];
}
}
return [
'genericData' => $data,
'userData' => $userData ?? null
];
};

View file

@ -1,7 +1,15 @@
<?php
if (!$kirby->user()) {
return json_encode([
'page' => $genericData,
'user' => []
]);
}
function getProjectData($project)
{
{
$data = [
'title' => $project->title()->value(),
'url' => $project->url(),

View file

@ -1,9 +1,9 @@
import { createWebHistory, createRouter } from "vue-router";
import routes from "./routes";
import { useApiStore } from "../stores/api";
import { usePageStore } from "../stores/page";
import { useUserStore } from "../stores/user";
import { getActivePinia } from "pinia";
import { createWebHistory, createRouter } from 'vue-router';
import routes from './routes';
import { useApiStore } from '../stores/api';
import { usePageStore } from '../stores/page';
import { useUserStore } from '../stores/user';
import { getActivePinia } from 'pinia';
const router = createRouter({
history: createWebHistory(),
@ -12,10 +12,14 @@ const router = createRouter({
router.beforeEach(async (to, from, next) => {
const pinia = getActivePinia();
const api = useApiStore(pinia);
const pageStore = usePageStore(pinia);
const userStore = useUserStore(pinia);
if (to.path === '/login') next();
if (!userStore.user) next('/login');
const api = useApiStore(pinia);
try {
const res = await api.fetchData(to.path);

View file

@ -13,6 +13,7 @@ const routes = [
component: Home,
},
{
name: 'Login',
path: '/login',
component: Login,
},