From dfcad5bb98e0c12e0e2328da8199828db20daf71 Mon Sep 17 00:00:00 2001 From: dawn Date: Wed, 23 Sep 2026 10:26:01 +0300 Subject: [PATCH] web: reuse the personal session for its own account Signed-off-by: dawn --- web/src/lib/api/actAs.test.ts | 9 +++++++++ web/src/lib/api/actAs.ts | 1 + web/src/lib/components/repo/RepoCreationForm.svelte | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/web/src/lib/api/actAs.test.ts b/web/src/lib/api/actAs.test.ts index 196cd958d..6c67d2fee 100644 --- a/web/src/lib/api/actAs.test.ts +++ b/web/src/lib/api/actAs.test.ts @@ -164,6 +164,15 @@ describe("createDelegatedSession", () => { describe("getOrCreateDelegatedSession", () => { const controllerAgent = controllerAgentOn("https://pds.example"); + it("keeps the personal session when the owner is the controller", async () => { + const agent = await getOrCreateDelegatedSession(controllerAgent, controllerDid); + + expect(agent).toBe(controllerAgent); + expect(getSession).not.toHaveBeenCalled(); + expect(deleteStoredSession).not.toHaveBeenCalled(); + expect(createAuthorizationUrl).not.toHaveBeenCalled(); + }); + it("reuses a stored session minted by this controller", async () => { const stored = orgSession(controllerDid); vi.mocked(getSession).mockResolvedValue(stored); diff --git a/web/src/lib/api/actAs.ts b/web/src/lib/api/actAs.ts index afc3eb149..d249eaeb1 100644 --- a/web/src/lib/api/actAs.ts +++ b/web/src/lib/api/actAs.ts @@ -190,6 +190,7 @@ export const getOrCreateDelegatedSession = async ( delegatedDid: Did ): Promise => { const controllerDid = controllerAgent.sub as Did; + if (delegatedDid === controllerDid) return controllerAgent; const stored = await storedDelegatedSession(controllerDid, delegatedDid); const agent = stored ? new OAuthUserAgent(stored) diff --git a/web/src/lib/components/repo/RepoCreationForm.svelte b/web/src/lib/components/repo/RepoCreationForm.svelte index ab0dd7af0..8b8b8f68d 100644 --- a/web/src/lib/components/repo/RepoCreationForm.svelte +++ b/web/src/lib/components/repo/RepoCreationForm.svelte @@ -114,7 +114,7 @@ }); const agentForOwner = async (ownerDid: Did, options?: { relogin?: boolean }) => { if (!user) throw new Error("Sign in to continue."); - if (auth.accounts.some((account) => account.did === ownerDid)) + if (ownerDid === user.did || auth.accounts.some((account) => account.did === ownerDid)) return auth.agentFor(ownerDid, options); return getOrCreateDelegatedSession(await auth.agentFor(user.did, options), ownerDid); }; -- 2.51.2