staging-tester / ocean-landing-serve / src/ routes/ sign-in/ +page.ts

import { redirect } from '@sveltejs/kit';
import { loadMe } from '#lib/live/identity.svelte.js';
import type { PageLoad } from './$types';

// Whether you are signed in is only known to the browser's cookie, so this page renders there.
export const ssr = false;

const flows = ['github_error', 'second-factor', 'link'];

// Someone already signed in goes on to where they were headed; a GitHub flow returning here still needs the page.
export const load: PageLoad = async ({ url }) => {
	if (flows.some((f) => url.searchParams.has(f))) return;
	const me = await loadMe().catch(() => null);
	if (!me) return;
	const to = url.searchParams.get('next') ?? '';
	redirect(307, to.startsWith('/') && !to.startsWith('//') && !to.startsWith('/\\') ? to : `/${me.handle}`);
};