import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';

export const load: PageServerLoad = async ({ locals, url }) => {
	// Already logged in — send to home
	if (locals.user) {
		redirect(302, '/');
	}
	// Surface provider error codes to the page (oauth_state, oauth_failed, etc.)
	const error = url.searchParams.get('error') ?? undefined;
	return { error };
};
