22 lines
752 B
TypeScript
22 lines
752 B
TypeScript
// src/routes/my-page/+page.server.ts
|
|
import type { PageServerLoad } from './$types';
|
|
|
|
export const load: PageServerLoad = async ({ locals }) => {
|
|
// get the logged-in user
|
|
const { data: { user }, error: authError } = await locals.supabase.auth.getUser();
|
|
|
|
const { data: user_profile, error: profileError } = await locals.supabase.from('profiles').select('*, section:sections (id, name)').eq('id', user?.id).single();
|
|
|
|
if (authError) {
|
|
console.error('Supabase auth error:', authError);
|
|
throw new Error('Could not get user');
|
|
}
|
|
|
|
if (profileError) {
|
|
console.error('Supabase profile error:', profileError);
|
|
throw new Error('Could not get user profile');
|
|
}
|
|
|
|
return { user, user_profile };
|
|
|
|
}; |