your personal website on atproto - mirror blento.app
26
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #302 from flo-bit/fix/redirect-to-login-from-edit

add login page, redirect to login page when going to {user}/edit and …

authored by

Florian and committed by
GitHub
dc165249 13f84dca

+71 -4
-1
src/lib/cards/media/SecretImageCard/EditingSecretImageCard.svelte
··· 38 38 }; 39 39 }); 40 40 41 - // eslint-disable-next-line @typescript-eslint/no-explicit-any 42 41 async function decryptImage(password: string, blob: any) { 43 42 try { 44 43 const url = await getBlobURL({ did, blob });
+17
src/routes/(auth)/login/+page.server.ts
··· 1 + import { env } from '$env/dynamic/private'; 2 + import { env as publicEnv } from '$env/dynamic/public'; 3 + import { error, redirect } from '@sveltejs/kit'; 4 + import { getDetailedProfile } from '$lib/atproto/methods'; 5 + 6 + export async function load({ locals, request }) { 7 + if (env.PUBLIC_IS_SELFHOSTED) error(404); 8 + 9 + if (locals.did) { 10 + const profile = await getDetailedProfile({ did: locals.did }).catch(() => undefined); 11 + const actor = 12 + profile?.handle && profile.handle !== 'handle.invalid' ? profile.handle : locals.did; 13 + const customDomain = request.headers.get('X-Custom-Domain'); 14 + const canonical = publicEnv.PUBLIC_DOMAIN || 'https://blento.app'; 15 + redirect(303, customDomain ? `${canonical}/${actor}/edit` : `/${actor}/edit`); 16 + } 17 + }
+41
src/routes/(auth)/login/+page.svelte
··· 1 + <script lang="ts"> 2 + import { AtprotoLogin } from '@foxui/social'; 3 + import { login, signup } from '$lib/atproto'; 4 + import type { ActorIdentifier } from '@atcute/lexicons'; 5 + import MadeWithBlento from '$lib/website/MadeWithBlento.svelte'; 6 + </script> 7 + 8 + <svelte:head> 9 + <title>Login &middot; blento</title> 10 + <meta name="description" content="Login to blento with your atmosphere account." /> 11 + </svelte:head> 12 + 13 + <div 14 + class="bg-base-100 dark:bg-base-950 text-base-900 dark:text-base-50 flex min-h-screen flex-col px-4 py-12 lg:px-8" 15 + > 16 + <div class="mx-auto w-full max-w-md flex-1"> 17 + <a 18 + href="/" 19 + class="text-base-500 hover:text-base-900 dark:hover:text-base-100 mb-8 inline-block text-sm transition-colors" 20 + > 21 + &larr; Back to blento 22 + </a> 23 + 24 + <div 25 + class="bg-base-50 dark:bg-base-900 border-base-200 dark:border-base-800 rounded-2xl border p-6 shadow-sm sm:p-8" 26 + > 27 + <AtprotoLogin 28 + login={async (handle) => { 29 + await login(handle as ActorIdentifier); 30 + return true; 31 + }} 32 + signup={async () => { 33 + await signup(); 34 + return true; 35 + }} 36 + /> 37 + </div> 38 + </div> 39 + 40 + <MadeWithBlento class="text-base-500 mt-16 text-center" /> 41 + </div>
+3 -1
src/routes/(auth)/oauth/callback/+server.ts
··· 4 4 import { scopes } from '$lib/atproto/server/scopes'; 5 5 import { getDetailedProfile } from '$lib/atproto/methods'; 6 6 import { dev } from '$app/environment'; 7 + import { env as publicEnv } from '$env/dynamic/public'; 7 8 import type { Did } from '@atcute/lexicons'; 8 9 import type { RequestHandler } from './$types'; 9 10 ··· 33 34 34 35 const profile = await getDetailedProfile({ did }).catch(() => undefined); 35 36 const actor = profile?.handle && profile.handle !== 'handle.invalid' ? profile.handle : did; 36 - redirect(303, `/${actor}/edit`); 37 + const canonical = publicEnv.PUBLIC_DOMAIN || 'https://blento.app'; 38 + redirect(303, customDomain ? `${canonical}/${actor}/edit` : `/${actor}/edit`); 37 39 };
+10 -2
src/routes/[[actor=actor]]/(pages)/+layout.server.ts
··· 1 1 import { loadData } from '$lib/website/load'; 2 2 import { env } from '$env/dynamic/private'; 3 - import { error } from '@sveltejs/kit'; 3 + import { env as publicEnv } from '$env/dynamic/public'; 4 + import { error, redirect } from '@sveltejs/kit'; 4 5 import { createCache } from '$lib/cache'; 5 6 import { getActor } from '$lib/actor.js'; 6 7 import { logPageview } from '$lib/analytics'; ··· 18 19 19 20 const data = await loadData(actor, cache, params.page, env, platform); 20 21 21 - const isInteractiveRoute = route.id?.endsWith('/edit') || route.id?.endsWith('/copy') || false; 22 + const isEditRoute = route.id?.endsWith('/edit') || false; 23 + const isInteractiveRoute = isEditRoute || route.id?.endsWith('/copy') || false; 22 24 const isAnonymous = !locals.did; 25 + 26 + if (isEditRoute && locals.did !== data.did) { 27 + const customDomain = request.headers.get('X-Custom-Domain'); 28 + const canonical = publicEnv.PUBLIC_DOMAIN || 'https://blento.app'; 29 + redirect(303, customDomain ? `${canonical}/login` : '/login'); 30 + } 23 31 24 32 if (isAnonymous && !isInteractiveRoute) { 25 33 setHeaders({