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