feat(#14): Replace profile page with account page

This commit is contained in:
Josh Creek
2024-07-04 19:33:51 +01:00
parent 113268614b
commit f10e0537bd
5 changed files with 121 additions and 18 deletions
+55
View File
@@ -0,0 +1,55 @@
import { fail, redirect } from '@sveltejs/kit';
import type { Actions, PageServerLoad } from './$types';
export const load: PageServerLoad = async ({ locals: { supabase, safeGetSession } }) => {
const { session } = await safeGetSession();
if (!session) {
redirect(303, '/');
}
const { data: profile } = await supabase
.from('profiles')
.select(`username, full_name`)
.eq('id', session.user.id)
.single();
return { session, profile };
};
export const actions: Actions = {
update: async ({ request, locals: { supabase, safeGetSession } }) => {
const formData = await request.formData();
const fullName = formData.get('fullName') as string;
const { session } = await safeGetSession();
const { error } = await supabase.from('profiles').upsert({
id: session?.user.id,
full_name: fullName,
username: session?.user.email,
updated_at: new Date()
});
console.error(error);
if (error) {
return fail(500, {
fullName,
username: session?.user.email
});
}
return {
fullName,
username: session?.user.email
};
},
signout: async ({ locals: { supabase, safeGetSession } }) => {
const { session } = await safeGetSession();
if (session) {
await supabase.auth.signOut();
redirect(303, '/');
}
}
};