Supbase login + waiting list page

This commit is contained in:
rotimi-best
2021-07-31 23:06:14 +03:00
parent 302b2eb37b
commit 4ebd98657f
31 changed files with 7488 additions and 397 deletions
+77 -7
View File
@@ -1,14 +1,83 @@
<script context="module">
export function preload(page, { config }) {
return { config };
}
</script>
<script>
import { stores } from '@sapper/app';
import { onMount } from 'svelte';
import { stores, goto } from '@sapper/app';
import Tailwindcss from '../components/Tailwindcss.svelte';
import Navigation from '../components/Navigation/index.svelte';
// import SideBar from "../components/SideBar/index.svelte";
import Footer from '../components/Footer/index.svelte';
import Apps from '../components/Apps/index.svelte';
import { handleAuthChange } from '../utils/functions/api';
import { user, profile } from '../utils/store/user';
import { getSupabase } from '../utils/functions/supabase';
export let segment;
export let config;
let supabase = getSupabase(config);
let { page } = stores();
let path = $page.path.replace('/', '');
async function getProfile() {
// Get user profile
const authUser = supabase.auth.user();
// Check if user has profile
let {
data: profileData,
error,
status,
} = await supabase
.from('profile')
.select(`*`)
.eq('user_id', authUser.id)
.single();
if (error && !profileData && status === 406) {
// User wasn't found, create profile
const { data, error } = await supabase
.from('profile')
.insert([{ user_id: authUser.id }]);
// Profile created, go to profile page
if (!error && data) {
user.set(authUser);
profile.set(data);
return goto('/');
}
} else if (profileData) {
// Profile exists, go to profile page
user.set(authUser);
profile.set(profileData);
return goto('/');
}
}
onMount(() => {
const { data: authListener } = supabase.auth.onAuthStateChange(
(event, session) => {
handleAuthChange(event, session);
if (event === 'SIGNED_IN') {
getProfile();
} else {
return goto('/');
}
}
);
return () => {
authListener.unsubscribe();
};
});
$: path = $page.path.replace('/', '');
</script>
<Tailwindcss />
@@ -16,26 +85,27 @@
<!-- <Nav {segment} /> -->
<main>
{#if !['login', 'signup'].includes($page.path.replace('/', ''))}
{#if !['login', 'signup', ''].includes(path)}
<Navigation {segment} />
{/if}
<div class="flex justify-between">
<slot />
{#if $page.path.includes('courses')}
{#if path.includes('courses')}
<Apps />
{/if}
</div>
</main>
<Footer />
{#if !['about', ''].includes(path)}
<Footer {segment} />
{/if}
<style>
main {
background-color: white;
/* padding: 15px 2em; */
/* margin: 0 auto; */
box-sizing: border-box;
/* max-width: 900px; */
}
:global(a:hover) {