Allow only users via mvp

This commit is contained in:
rotimi-best
2021-08-18 20:23:56 +03:00
parent 60f06d6ab1
commit 67f4c938ea
3 changed files with 22 additions and 4 deletions
+2 -1
View File
@@ -5,6 +5,7 @@
import PrimaryButton from '../PrimaryButton/index.svelte'; import PrimaryButton from '../PrimaryButton/index.svelte';
export let segment; export let segment;
export let disableLogin;
let navClass = ''; let navClass = '';
@@ -86,7 +87,7 @@
className="mr-2" className="mr-2"
/> />
</a> </a>
{:else} {:else if !disableLogin}
<PrimaryButton <PrimaryButton
label="Login" label="Login"
className="py-2 px-4" className="py-2 px-4"
+18 -3
View File
@@ -1,6 +1,7 @@
<script context="module"> <script context="module">
export function preload(page, { config }) { export function preload(page, { config }) {
return { config }; console.log(`page`, page);
return { config, isMvpUser: !!page.query.mvp };
} }
</script> </script>
@@ -18,10 +19,12 @@
export let segment; export let segment;
export let config; export let config;
export let isMvpUser;
let supabase = getSupabase(config); let supabase = getSupabase(config);
let { page } = stores(); let { page } = stores();
let path = $page.path.replace('/', ''); let path = $page.path.replace('/', '');
let allowUser = false;
async function getProfile() { async function getProfile() {
console.log('Get user profile'); console.log('Get user profile');
@@ -80,7 +83,19 @@
} }
onMount(() => { 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( const { data: authListener } = supabase.auth.onAuthStateChange(
(event, session) => { (event, session) => {
handleAuthChange(event, session); handleAuthChange(event, session);
@@ -109,7 +124,7 @@
<main> <main>
{#if !['login', 'signup'].includes(path)} {#if !['login', 'signup'].includes(path)}
<Navigation {segment} /> <Navigation {segment} disableLogin={!allowUser} />
{/if} {/if}
<div class="flex justify-between"> <div class="flex justify-between">
+2
View File
@@ -7,6 +7,7 @@
import PrimaryButton from '../components/PrimaryButton/index.svelte'; import PrimaryButton from '../components/PrimaryButton/index.svelte';
import { VARIANTS } from '../components/PrimaryButton/constants'; import { VARIANTS } from '../components/PrimaryButton/constants';
import { getSupabase } from '../utils/functions/supabase'; import { getSupabase } from '../utils/functions/supabase';
import { validateEmail } from '../utils/functions/validateEmail';
let email; let email;
let isAdding = false; let isAdding = false;
@@ -33,6 +34,7 @@
]; ];
async function handleSubmit() { async function handleSubmit() {
if (!email || !validateEmail(email)) return;
isAdding = true; isAdding = true;
await supabase await supabase