Skip to content

Instantly share code, notes, and snippets.

@kellenmace
Last active August 8, 2022 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kellenmace/07b512319d6eebbc910a0fcb5f4df037 to your computer and use it in GitHub Desktop.
Save kellenmace/07b512319d6eebbc910a0fcb5f4df037 to your computer and use it in GitHub Desktop.
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