From 67f4c938ea563c948b214529b7505914e5bb8555 Mon Sep 17 00:00:00 2001 From: rotimi-best Date: Wed, 18 Aug 2021 20:23:56 +0300 Subject: [PATCH] Allow only users via mvp --- src/components/Navigation/index.svelte | 3 ++- src/routes/_layout.svelte | 21 ++++++++++++++++++--- src/routes/index.svelte | 2 ++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/components/Navigation/index.svelte b/src/components/Navigation/index.svelte index e231a09b..3748f9f4 100644 --- a/src/components/Navigation/index.svelte +++ b/src/components/Navigation/index.svelte @@ -5,6 +5,7 @@ import PrimaryButton from '../PrimaryButton/index.svelte'; export let segment; + export let disableLogin; let navClass = ''; @@ -86,7 +87,7 @@ className="mr-2" /> - {:else} + {:else if !disableLogin} export function preload(page, { config }) { - return { config }; + console.log(`page`, page); + return { config, isMvpUser: !!page.query.mvp }; } @@ -18,10 +19,12 @@ export let segment; export let config; + export let isMvpUser; let supabase = getSupabase(config); let { page } = stores(); let path = $page.path.replace('/', ''); + let allowUser = false; async function getProfile() { console.log('Get user profile'); @@ -80,7 +83,19 @@ } onMount(() => { - console.log('mounting layout'); + console.log('mounting layout', isMvpUser, path); + const _isMvpUser = localStorage.getItem('mvp'); + if (isMvpUser) { + localStorage.setItem('mvp', 'true'); + allowUser = true; + } else if (!_isMvpUser) { + if (!!path) { + goto('/'); + } + + return; + } + const { data: authListener } = supabase.auth.onAuthStateChange( (event, session) => { handleAuthChange(event, session); @@ -109,7 +124,7 @@
{#if !['login', 'signup'].includes(path)} - + {/if}
diff --git a/src/routes/index.svelte b/src/routes/index.svelte index 490a19a8..ee5cfbab 100644 --- a/src/routes/index.svelte +++ b/src/routes/index.svelte @@ -7,6 +7,7 @@ import PrimaryButton from '../components/PrimaryButton/index.svelte'; import { VARIANTS } from '../components/PrimaryButton/constants'; import { getSupabase } from '../utils/functions/supabase'; + import { validateEmail } from '../utils/functions/validateEmail'; let email; let isAdding = false; @@ -33,6 +34,7 @@ ]; async function handleSubmit() { + if (!email || !validateEmail(email)) return; isAdding = true; await supabase