From 7eec86d4529d32b415e445c38650119a395b228b Mon Sep 17 00:00:00 2001 From: Florian <45694132+flo-bit@users.noreply.github.com> Date: Mon, 4 May 2026 21:16:53 +0200 Subject: [PATCH] add login page, redirect to login page when going to {user}/edit and not logged in as that user --- .../EditingSecretImageCard.svelte | 1 - src/routes/(auth)/login/+page.server.ts | 17 ++++++++ src/routes/(auth)/login/+page.svelte | 41 +++++++++++++++++++ src/routes/(auth)/oauth/callback/+server.ts | 4 +- .../[[actor=actor]]/(pages)/+layout.server.ts | 12 +++++- 5 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 src/routes/(auth)/login/+page.server.ts create mode 100644 src/routes/(auth)/login/+page.svelte diff --git a/src/lib/cards/media/SecretImageCard/EditingSecretImageCard.svelte b/src/lib/cards/media/SecretImageCard/EditingSecretImageCard.svelte index bed6357..a5a4af8 100644 --- a/src/lib/cards/media/SecretImageCard/EditingSecretImageCard.svelte +++ b/src/lib/cards/media/SecretImageCard/EditingSecretImageCard.svelte @@ -38,7 +38,6 @@ }; }); - // eslint-disable-next-line @typescript-eslint/no-explicit-any async function decryptImage(password: string, blob: any) { try { const url = await getBlobURL({ did, blob }); diff --git a/src/routes/(auth)/login/+page.server.ts b/src/routes/(auth)/login/+page.server.ts new file mode 100644 index 0000000..dbf8537 --- /dev/null +++ b/src/routes/(auth)/login/+page.server.ts @@ -0,0 +1,17 @@ +import { env } from '$env/dynamic/private'; +import { env as publicEnv } from '$env/dynamic/public'; +import { error, redirect } from '@sveltejs/kit'; +import { getDetailedProfile } from '$lib/atproto/methods'; + +export async function load({ locals, request }) { + if (env.PUBLIC_IS_SELFHOSTED) error(404); + + if (locals.did) { + const profile = await getDetailedProfile({ did: locals.did }).catch(() => undefined); + const actor = + profile?.handle && profile.handle !== 'handle.invalid' ? profile.handle : locals.did; + const customDomain = request.headers.get('X-Custom-Domain'); + const canonical = publicEnv.PUBLIC_DOMAIN || 'https://blento.app'; + redirect(303, customDomain ? `${canonical}/${actor}/edit` : `/${actor}/edit`); + } +} diff --git a/src/routes/(auth)/login/+page.svelte b/src/routes/(auth)/login/+page.svelte new file mode 100644 index 0000000..aeb4a19 --- /dev/null +++ b/src/routes/(auth)/login/+page.svelte @@ -0,0 +1,41 @@ + + + + Login · blento + + + +
+
+ + ← Back to blento + + +
+ { + await login(handle as ActorIdentifier); + return true; + }} + signup={async () => { + await signup(); + return true; + }} + /> +
+
+ + +
diff --git a/src/routes/(auth)/oauth/callback/+server.ts b/src/routes/(auth)/oauth/callback/+server.ts index 0f31252..b048bde 100644 --- a/src/routes/(auth)/oauth/callback/+server.ts +++ b/src/routes/(auth)/oauth/callback/+server.ts @@ -4,6 +4,7 @@ import { setSignedCookie } from '$lib/atproto/server/signed-cookie'; import { scopes } from '$lib/atproto/server/scopes'; import { getDetailedProfile } from '$lib/atproto/methods'; import { dev } from '$app/environment'; +import { env as publicEnv } from '$env/dynamic/public'; import type { Did } from '@atcute/lexicons'; import type { RequestHandler } from './$types'; @@ -33,5 +34,6 @@ export const GET: RequestHandler = async ({ url, platform, cookies, request }) = const profile = await getDetailedProfile({ did }).catch(() => undefined); const actor = profile?.handle && profile.handle !== 'handle.invalid' ? profile.handle : did; - redirect(303, `/${actor}/edit`); + const canonical = publicEnv.PUBLIC_DOMAIN || 'https://blento.app'; + redirect(303, customDomain ? `${canonical}/${actor}/edit` : `/${actor}/edit`); }; diff --git a/src/routes/[[actor=actor]]/(pages)/+layout.server.ts b/src/routes/[[actor=actor]]/(pages)/+layout.server.ts index 1ef6ed9..34467eb 100644 --- a/src/routes/[[actor=actor]]/(pages)/+layout.server.ts +++ b/src/routes/[[actor=actor]]/(pages)/+layout.server.ts @@ -1,6 +1,7 @@ import { loadData } from '$lib/website/load'; import { env } from '$env/dynamic/private'; -import { error } from '@sveltejs/kit'; +import { env as publicEnv } from '$env/dynamic/public'; +import { error, redirect } from '@sveltejs/kit'; import { createCache } from '$lib/cache'; import { getActor } from '$lib/actor.js'; import { logPageview } from '$lib/analytics'; @@ -18,9 +19,16 @@ export async function load({ params, platform, request, locals, route, setHeader const data = await loadData(actor, cache, params.page, env, platform); - const isInteractiveRoute = route.id?.endsWith('/edit') || route.id?.endsWith('/copy') || false; + const isEditRoute = route.id?.endsWith('/edit') || false; + const isInteractiveRoute = isEditRoute || route.id?.endsWith('/copy') || false; const isAnonymous = !locals.did; + if (isEditRoute && locals.did !== data.did) { + const customDomain = request.headers.get('X-Custom-Domain'); + const canonical = publicEnv.PUBLIC_DOMAIN || 'https://blento.app'; + redirect(303, customDomain ? `${canonical}/login` : '/login'); + } + if (isAnonymous && !isInteractiveRoute) { setHeaders({ 'Cache-Control': 'public, s-maxage=60, stale-while-revalidate=600' -- 2.54.0