Last active
August 8, 2022 13:44
-
-
Save kellenmace/07b512319d6eebbc910a0fcb5f4df037 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { supabase } from '$lib/supabaseClient'; | |
import type { AuthUser } from '@supabase/supabase-js'; | |
import { writable } from 'svelte/store'; | |
import type { Profile } from '../types/supabase'; | |
interface User extends Omit<AuthUser, 'email'>, Profile {}; | |
export const user = writable<User | undefined>(undefined); | |
supabase.auth.onAuthStateChange(async (event, session) => { | |
switch (event) { | |
case 'SIGNED_IN': { | |
const { data: profile } = await supabase | |
.from('profiles') | |
.select('*') | |
.eq('id', session.user.id) | |
.single(); | |
user.set({...session.user, ...profile}); | |
break; | |
} | |
case 'SIGNED_OUT': | |
user.set(undefined); | |
break; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment