replies timeline only, appview-less bluesky client

fix: properly resume oauth session

ptr.pet 1731f8cd 431f3f26

verified
Changed files
+12 -14
src
+1 -1
src/components/BskyPost.svelte
···
isOnPostComposer = false /* replyBacklinks */
}: Props = $props();
-
const selectedDid = $derived(client.didDoc?.did ?? null);
+
const selectedDid = $derived(client.user?.did ?? null);
const aturi: CanonicalResourceUri = `at://${did}/app.bsky.feed.post/${rkey}`;
const color = generateColorForDid(did);
+2 -2
src/components/PostComposer.svelte
···
}: Props = $props();
let color = $derived(
-
client.didDoc?.did ? generateColorForDid(client.didDoc?.did) : 'var(--nucleus-accent2)'
+
client.user?.did ? generateColorForDid(client.user?.did) : 'var(--nucleus-accent2)'
);
const post = async (text: string): Promise<Result<PostWithUri, string>> => {
···
const res = await client.atcute?.post('com.atproto.repo.createRecord', {
input: {
collection: 'app.bsky.feed.post',
-
repo: client.didDoc!.did,
+
repo: client.user!.did,
record
}
});
+8 -10
src/lib/at/client.ts
···
export class AtpClient {
public atcute: AtcuteClient | null = null;
-
public didDoc: MiniDoc | null = null;
+
public user: { did: Did; handle: Handle } | null = null;
async login(identifier: ActorIdentifier, agent: OAuthUserAgent): Promise<Result<null, string>> {
-
if ((agent.session.token.expires_at ?? 0) < Date.now()) {
-
return err('token expired, relogin');
-
}
-
-
const didDoc = await this.resolveDidDoc(identifier);
-
if (!didDoc.ok) return err(didDoc.error);
-
this.didDoc = didDoc.value;
-
try {
const rpc = new AtcuteClient({ handler: agent });
+
const res = await rpc.get('com.atproto.server.getSession');
+
if (!res.ok) throw res.data.error;
+
this.user = {
+
did: res.data.did,
+
handle: res.data.handle
+
};
this.atcute = rpc;
} catch (error) {
return err(`failed to login: ${error}`);
···
}
async getProfile(repo?: ActorIdentifier): Promise<Result<AppBskyActorProfile.Main, string>> {
-
repo = repo ?? this.didDoc?.did;
+
repo = repo ?? this.user?.did;
if (!repo) return err('not authenticated');
return map(await this.getRecord(AppBskyActorProfile.mainSchema, repo, 'self'), (d) => d.record);
}
+1 -1
src/routes/+page.svelte
···
if ($accounts.length > 0) {
loaderState.status = 'LOADING';
if (loadData.client.ok && loadData.client.value) {
-
const loggedInDid = loadData.client.value.didDoc!.did as AtprotoDid;
+
const loggedInDid = loadData.client.value.user!.did as AtprotoDid;
selectedDid = loggedInDid;
clients.set(loggedInDid, loadData.client.value);
}