From 8cd8b90e4e8ec64417d3c70a264e962741f7fb2c Mon Sep 17 00:00:00 2001 From: Florian <45694132+flo-bit@users.noreply.github.com> Date: Wed, 28 Jan 2026 12:06:37 +0100 Subject: [PATCH] fixes --- README.md | 14 +++++----- src/lib/{ => atproto}/UI/Avatar.svelte | 0 src/lib/{ => atproto}/UI/Button.svelte | 0 src/lib/{ => atproto}/UI/HandleInput.svelte | 0 src/lib/{ => atproto}/UI/LoginModal.svelte | 5 +++- .../{ => atproto}/UI/SecondaryButton.svelte | 0 src/lib/atproto/UI/index.ts | 1 + src/lib/atproto/auth.svelte.ts | 28 +++++++++++++------ src/lib/atproto/metadata.ts | 8 +++--- src/lib/atproto/methods.ts | 2 +- src/lib/atproto/settings.ts | 13 +++++++-- src/routes/+layout.svelte | 2 +- src/routes/+page.svelte | 14 ++++------ 13 files changed, 53 insertions(+), 34 deletions(-) rename src/lib/{ => atproto}/UI/Avatar.svelte (100%) rename src/lib/{ => atproto}/UI/Button.svelte (100%) rename src/lib/{ => atproto}/UI/HandleInput.svelte (100%) rename src/lib/{ => atproto}/UI/LoginModal.svelte (97%) rename src/lib/{ => atproto}/UI/SecondaryButton.svelte (100%) create mode 100644 src/lib/atproto/UI/index.ts diff --git a/README.md b/README.md index e731f70..389697f 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ const config = { 7. setup the correct permissions (see below) -### or manually install in your own project +### or manually add to your own project 1. copy the `src/lib/atproto` folder into your own project 2. also copy the `src/routes/oauth-client-metadata.json` folder into your project @@ -72,7 +72,7 @@ export default defineConfig({ npm install @atcute/atproto @atcute/bluesky @atcute/identity-resolver @atcute/lexicons @atcute/oauth-browser-client @atcute/client ``` -6. (optionally) set your base in `svelte.config.js` (e.g. for github pages: `base: '/your-repo-name/'`) while keeping it as `''` in development. +6. (optionally) set your base in `svelte.config.js` (e.g. for deploying to github pages: `base: '/your-repo-name/'`) while keeping it as `''` in development. ```ts const config = { @@ -102,7 +102,7 @@ const config = { ### change sign up pds -If you want to allow sign-up, change the `signUpPDS` variable in `$lib/atproto/settings.ts` to a pds of your choice +If you want to allow sign-up, change the `devPDS` and `prodPDS` variables in `$lib/atproto/settings.ts` to a pds of your choice ATTENTION: the current setting (pds.rip) is only for development, all accounts get deleted automatically after a week @@ -115,18 +115,18 @@ Either use the `LoginModal` component to render a login modal or use the `user` import { user } from '$lib/atproto'; // methods: +user.isInitializing; +user.isLoggedIn; user.login(handle); user.signup(); -user.isLoggedIn; user.logout(); ``` -LoginModal is a component that renders a login modal, add it for a quick login flow (needs tailwind). -(copy the `src/lib/UI` folder into your projects `src/lib` folder, add the `src/app.css` content to your `app.css`) +LoginModal is a component that renders a login modal, add it for a quick login flow (needs tailwind and tailwind/forms, copy the `src/app.css` content to your `app.css`). ```svelte diff --git a/src/lib/UI/Avatar.svelte b/src/lib/atproto/UI/Avatar.svelte similarity index 100% rename from src/lib/UI/Avatar.svelte rename to src/lib/atproto/UI/Avatar.svelte diff --git a/src/lib/UI/Button.svelte b/src/lib/atproto/UI/Button.svelte similarity index 100% rename from src/lib/UI/Button.svelte rename to src/lib/atproto/UI/Button.svelte diff --git a/src/lib/UI/HandleInput.svelte b/src/lib/atproto/UI/HandleInput.svelte similarity index 100% rename from src/lib/UI/HandleInput.svelte rename to src/lib/atproto/UI/HandleInput.svelte diff --git a/src/lib/UI/LoginModal.svelte b/src/lib/atproto/UI/LoginModal.svelte similarity index 97% rename from src/lib/UI/LoginModal.svelte rename to src/lib/atproto/UI/LoginModal.svelte index e2c7c87..886b6de 100644 --- a/src/lib/UI/LoginModal.svelte +++ b/src/lib/atproto/UI/LoginModal.svelte @@ -122,7 +122,9 @@ {#if showRecentLogins}
Recent logins
- {#each Object.values(recentLogins).slice(0, 4) as recentLogin} + {#each Object.values(recentLogins) + .filter((l) => l.handle && l.handle !== 'handle.invalid') + .slice(0, 4) as recentLogin}
'repo:' + collection).join(' '); @@ -14,9 +14,9 @@ function constructScope() { } let blobScope: string | undefined = undefined; - if (Array.isArray(permissions.blobs)) { + if (Array.isArray(permissions.blobs) && permissions.blobs.length > 0) { blobScope = 'blob?' + permissions.blobs.map((b) => 'accept=' + b).join('&'); - } else if (permissions.blobs) { + } else if (permissions.blobs && permissions.blobs.length > 0) { blobScope = 'blob:' + permissions.blobs; } @@ -26,7 +26,7 @@ function constructScope() { export const metadata = { client_id: SITE + resolve('/oauth-client-metadata.json'), - redirect_uris: [SITE + resolve('/')], + redirect_uris: [SITE + resolve(REDIRECT_PATH)], scope: constructScope(), grant_types: ['authorization_code', 'refresh_token'], response_types: ['code'], diff --git a/src/lib/atproto/methods.ts b/src/lib/atproto/methods.ts index 412633b..27c451b 100644 --- a/src/lib/atproto/methods.ts +++ b/src/lib/atproto/methods.ts @@ -304,7 +304,7 @@ export async function uploadBlob({ blob }: { blob: Blob }) { * @param did - The DID of the repository (defaults to current user) * @returns Repository metadata or undefined on failure */ -export async function describeRepo({ client, did }: { client: Client; did?: Did }) { +export async function describeRepo({ client, did }: { client?: Client; did?: Did }) { did ??= user.did; if (!did) { throw new Error('Error describeRepo: No did'); diff --git a/src/lib/atproto/settings.ts b/src/lib/atproto/settings.ts index 7acd705..f9ed671 100644 --- a/src/lib/atproto/settings.ts +++ b/src/lib/atproto/settings.ts @@ -1,3 +1,5 @@ +import { dev } from '$app/environment'; + export const SITE = 'https://flo-bit.dev'; type Permissions = { @@ -25,7 +27,7 @@ export const permissions = { // blobs: ['video/*', 'text/html'] // example: allowing all blob types // blobs: ['*/*'] - blobs: ['hello'] + blobs: [] } as const satisfies Permissions; // Extract base collection name (before any query params) @@ -35,4 +37,11 @@ export type AllowedCollection = ExtractCollectionBase<(typeof permissions.collec // which PDS to use for signup // ATTENTION: pds.rip is only for development, all accounts get deleted automatically after a week -export const signUpPDS = 'https://pds.rip/'; +const devPDS = 'https://pds.rip/'; +const prodPDS = 'https://selfhosted.social/'; +export const signUpPDS = dev ? devPDS : prodPDS; + +// where to redirect after oauth login/signup, e.g. /oauth/callback +export const REDIRECT_PATH = '/'; + +export const DOH_RESOLVER = 'https://mozilla.cloudflare-dns.com/dns-query'; diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index ec6a48b..fa05af9 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -3,7 +3,7 @@ import { onMount } from 'svelte'; import { initClient } from '$lib/atproto'; - import LoginModal from '$lib/UI/LoginModal.svelte'; + import LoginModal from '$lib/atproto/UI/LoginModal.svelte'; let { children } = $props(); diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 957742c..eff025d 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,13 +1,9 @@
@@ -24,8 +20,8 @@ {/if} {#if !user.isInitializing && !user.agent} -
not signed in
- +
not logged in
+ {/if} {#if user.isLoggedIn} -- 2.51.2