Allow only users via mvp
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user