From efcc2384b4037c3c2366bee4e25dc745fbaeb0f0 Mon Sep 17 00:00:00 2001 From: Nathan Colosimo <110621881+NathanColosimo@users.noreply.github.com> Date: Tue, 3 Mar 2026 22:20:39 -0500 Subject: [PATCH] fix(account): use accountId instead of id in accountInfo endpoint (#8346) Co-authored-by: Alex Yang --- .../src/api/routes/account.test.ts | 33 +++++++++++++++++++ .../better-auth/src/api/routes/account.ts | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/packages/better-auth/src/api/routes/account.test.ts b/packages/better-auth/src/api/routes/account.test.ts index 24cf5f7c9c..00e79cc8a7 100644 --- a/packages/better-auth/src/api/routes/account.test.ts +++ b/packages/better-auth/src/api/routes/account.test.ts @@ -193,6 +193,39 @@ describe("account", async () => { }); }); + /** + * @see https://github.com/better-auth/better-auth/issues/8345 + */ + it("should get account info using provider accountId (not internal id)", async () => { + const { runWithUser: runWithClient2 } = await signInWithTestUser(); + await runWithClient2(async () => { + const accounts = await client.listAccounts(); + const googleAccount = accounts.data?.find( + (a) => a.providerId === "google", + ); + expect(googleAccount).toBeDefined(); + + // The internal DB id must differ from the provider-issued accountId + expect(googleAccount!.id).not.toBe(googleAccount!.accountId); + + // accountInfo internally calls getAccessToken with account.accountId. + // Before the fix, it incorrectly passed account.id (internal DB id), + // causing getAccessToken to fail the account lookup. + const info = await client.$fetch("/account-info", { + query: { accountId: googleAccount!.accountId }, + method: "GET", + }); + + expect(info.data).toMatchObject({ + user: expect.objectContaining({ + id: expect.any(String), + email: expect.any(String), + }), + data: expect.any(Object), + }); + }); + }); + it("should pass custom scopes to authorization URL", async () => { const { runWithUser: runWithClient2 } = await signInWithTestUser(); await runWithClient2(async () => { diff --git a/packages/better-auth/src/api/routes/account.ts b/packages/better-auth/src/api/routes/account.ts index 800c6cabb0..2b88688a57 100644 --- a/packages/better-auth/src/api/routes/account.ts +++ b/packages/better-auth/src/api/routes/account.ts @@ -911,7 +911,7 @@ export const accountInfo = createAuthEndpoint( ...ctx, method: "POST", body: { - accountId: account.id, + accountId: account.accountId, providerId: account.providerId, }, returnHeaders: false,