Browse Source

Add return URL's to any unauthenticated requests in the portal or builder

gh-pages
Andrew Kingston 5 years ago
parent
commit
9cb06b296a
  1. 3
      packages/builder/src/pages/builder/_layout.svelte
  2. 18
      packages/builder/src/pages/builder/auth/_layout.svelte
  3. 12
      packages/builder/src/pages/builder/portal/_layout.svelte

3
packages/builder/src/pages/builder/_layout.svelte

@ -28,7 +28,8 @@
!$isActive("./auth") &&
!$isActive("./invite")
) {
$redirect("./auth/login")
const returnUrl = encodeURIComponent(window.location.pathname)
$redirect("./auth/login?", { returnUrl })
}
}
</script>

18
packages/builder/src/pages/builder/auth/_layout.svelte

@ -0,0 +1,18 @@
<script>
import { auth } from "stores/portal"
import { onMount } from "svelte"
import { redirect } from "@roxi/routify"
// If already authenticated, redirect away from the auth section.
// Check this onMount rather than a reactive statement to avoid trumping
// the login return URL functionality.
onMount(() => {
if ($auth.user) {
$redirect("../")
}
})
</script>
{#if !$auth.user}
<slot />
{/if}

12
packages/builder/src/pages/builder/portal/_layout.svelte

@ -37,11 +37,13 @@
onMount(async () => {
// Prevent non-builders from accessing the portal
if (!$auth.user?.builder?.global) {
$redirect("../")
} else {
await organisation.init()
loaded = true
if ($auth.user) {
if (!$auth.user?.builder?.global) {
$redirect("../")
} else {
await organisation.init()
loaded = true
}
}
})
</script>

Loading…
Cancel
Save