fix: block users from /workspace and /admin

This commit is contained in:
Timothy J. Baek 2024-08-02 18:08:23 +02:00
parent 4c1a9380e6
commit c6d7f24542
2 changed files with 147 additions and 124 deletions

View File

@ -1,11 +1,21 @@
<script lang="ts">
import { onMount, getContext } from 'svelte';
import { goto } from '$app/navigation';
import { WEBUI_NAME, showSidebar } from '$lib/stores';
import { WEBUI_NAME, showSidebar, user } from '$lib/stores';
import MenuLines from '$lib/components/icons/MenuLines.svelte';
import { page } from '$app/stores';
const i18n = getContext('i18n');
let loaded = false;
onMount(async () => {
if ($user?.role !== 'admin') {
await goto('/');
}
loaded = true;
});
</script>
<svelte:head>
@ -14,11 +24,12 @@
</title>
</svelte:head>
<div
{#if loaded}
<div
class=" flex flex-col w-full min-h-screen max-h-screen {$showSidebar
? 'md:max-w-[calc(100%-260px)]'
: ''}"
>
>
<div class=" px-4 pt-3 mt-0.5 mb-1">
<div class=" flex items-center gap-1">
<div class="{$showSidebar ? 'md:hidden' : ''} mr-1 self-start flex flex-none items-center">
@ -79,4 +90,5 @@
<div class=" py-1 px-5 flex-1 max-h-full overflow-y-auto">
<slot />
</div>
</div>
</div>
{/if}

View File

@ -1,15 +1,20 @@
<script lang="ts">
import { onMount, getContext } from 'svelte';
import { WEBUI_NAME, showSidebar, functions } from '$lib/stores';
import MenuLines from '$lib/components/icons/MenuLines.svelte';
import { WEBUI_NAME, showSidebar, functions, user } from '$lib/stores';
import { page } from '$app/stores';
import { getFunctions } from '$lib/apis/functions';
import { goto } from '$app/navigation';
import MenuLines from '$lib/components/icons/MenuLines.svelte';
const i18n = getContext('i18n');
let loaded = false;
onMount(async () => {
// functions.set(await getFunctions(localStorage.token));
if ($user?.role !== 'admin') {
await goto('/');
}
loaded = true;
});
</script>
@ -19,11 +24,12 @@
</title>
</svelte:head>
<div
{#if loaded}
<div
class=" flex flex-col w-full min-h-screen max-h-screen {$showSidebar
? 'md:max-w-[calc(100%-260px)]'
: ''}"
>
>
<div class=" px-4 pt-3 mt-0.5 mb-1">
<div class=" flex items-center gap-1">
<div class="{$showSidebar ? 'md:hidden' : ''} mr-1 self-start flex flex-none items-center">
@ -62,7 +68,9 @@
>
<a
class="min-w-fit rounded-lg p-1.5 px-3 {$page.url.pathname.includes('/workspace/documents')
class="min-w-fit rounded-lg p-1.5 px-3 {$page.url.pathname.includes(
'/workspace/documents'
)
? 'bg-gray-50 dark:bg-gray-850'
: ''} transition"
href="/workspace/documents"
@ -80,7 +88,9 @@
</a>
<a
class="min-w-fit rounded-lg p-1.5 px-3 {$page.url.pathname.includes('/workspace/functions')
class="min-w-fit rounded-lg p-1.5 px-3 {$page.url.pathname.includes(
'/workspace/functions'
)
? 'bg-gray-50 dark:bg-gray-850'
: ''} transition"
href="/workspace/functions"
@ -95,4 +105,5 @@
<div class=" py-1 px-5 flex-1 max-h-full overflow-y-auto">
<slot />
</div>
</div>
</div>
{/if}