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';
export let segment;
export let disableLogin;
let navClass = '';
@@ -86,7 +87,7 @@
className="mr-2"
/>
</a>
{:else}
{:else if !disableLogin}
<PrimaryButton
label="Login"
className="py-2 px-4"
+18 -3
View File
@@ -1,6 +1,7 @@
<script context="module">
export function preload(page, { config }) {
return { config };
console.log(`page`, page);
return { config, isMvpUser: !!page.query.mvp };
}
</script>
@@ -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 @@
<main>
{#if !['login', 'signup'].includes(path)}
<Navigation {segment} />
<Navigation {segment} disableLogin={!allowUser} />
{/if}
<div class="flex justify-between">
+2
View File
@@ -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