~james/core

core/web/src/routes/+layout.server.ts -rw-r--r-- 943 bytes
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 16 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { createBobbinClient } from "#lib/api/client.ts";
import { NUDGE_COOKIE } from "#lib/auth/onboarding.ts";
import { migrationPending } from "#lib/migration/status.ts";
import { getPublicConfig } from "#lib/server/config.ts";
import type { LayoutServerLoad } from "./$types";

export const load: LayoutServerLoad = async ({ cookies, fetch, platform }) => {
	const did = cookies.get("tangled.currentDid");
	const handle = cookies.get("tangled.currentHandle");
	const publicConfig = getPublicConfig(platform);

	// fail open, oauth writes go to the real pds either way
	const pending = did
		? await migrationPending(
				createBobbinClient({ serviceUrl: publicConfig.bobbinUrl, fetch }),
				did,
				publicConfig
			).catch(() => false)
		: false;

	return {
		publicConfig,
		auth: did ? { did, handle: handle ?? did } : null,
		migrationPending: pending,
		onboardingNudge: did !== undefined && cookies.get(NUDGE_COOKIE) === did
	};
};