Prevent flashing and intermittent errors when navigating to admin screens as a non admin

This commit is contained in:
Andrew Kingston 2021-05-24 12:40:36 +01:00
parent 0838a45efc
commit 1f1431344c
5 changed files with 80 additions and 92 deletions

View File

@ -0,0 +1,18 @@
<script>
import { Page } from "@budibase/bbui"
import { auth } from "stores/portal"
import { redirect } from "@roxi/routify"
// Only admins allowed here
$: {
if (!$auth.isAdmin) {
$redirect("../")
}
}
</script>
{#if $auth.isAdmin}
<Page>
<slot />
</Page>
{/if}

View File

@ -1,14 +0,0 @@
<script>
import { redirect } from "@roxi/routify"
import { Page } from "@budibase/bbui"
import { auth } from "../../../../../stores/portal"
// only admins allowed here
if (!$auth.isAdmin) {
$redirect("../../../portal")
}
</script>
<Page>
<slot />
</Page>

View File

@ -1,11 +1,5 @@
<script> <script>
import { redirect } from "@roxi/routify" import { email } from "stores/portal"
import { auth, email } from "stores/portal"
// only admins allowed here
if (!$auth.isAdmin) {
$redirect("../../../portal")
}
email.templates.fetch() email.templates.fetch()
</script> </script>

View File

@ -1,14 +0,0 @@
<script>
import { Page } from "@budibase/bbui"
import { auth } from "../../../../../stores/portal"
import { redirect } from "@roxi/routify"
// only admins allowed here
if (!$auth.isAdmin) {
$redirect("../../../portal")
}
</script>
<Page>
<slot />
</Page>

View File

@ -17,10 +17,12 @@
import { writable } from "svelte/store" import { writable } from "svelte/store"
import { redirect } from "@roxi/routify" import { redirect } from "@roxi/routify"
// only admins allowed here // Only admins allowed here
$: {
if (!$auth.isAdmin) { if (!$auth.isAdmin) {
$redirect("../../portal") $redirect("../../portal")
} }
}
const values = writable({ const values = writable({
analytics: !analytics.disabled(), analytics: !analytics.disabled(),
@ -70,7 +72,8 @@
} }
</script> </script>
<Layout> {#if $auth.isAdmin}
<Layout>
<Layout gap="XS" noPadding> <Layout gap="XS" noPadding>
<Heading size="M">Organisation</Heading> <Heading size="M">Organisation</Heading>
<Body> <Body>
@ -131,7 +134,8 @@
<div> <div>
<Button disabled={loading} on:click={saveConfig} cta>Save</Button> <Button disabled={loading} on:click={saveConfig} cta>Save</Button>
</div> </div>
</Layout> </Layout>
{/if}
<style> <style>
.fields { .fields {