fix(account): use accountId instead of id in accountInfo endpoint (#8346)

Co-authored-by: Alex Yang <himself65@outlook.com>
This commit is contained in:
Nathan Colosimo
2026-03-04 16:48:59 +09:00
committed by Alex Yang
co-authored by Alex Yang
parent e3bc6a2e5c
commit efcc2384b4
2 changed files with 34 additions and 1 deletions
@@ -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 () => {
@@ -911,7 +911,7 @@ export const accountInfo = createAuthEndpoint(
...ctx,
method: "POST",
body: {
accountId: account.id,
accountId: account.accountId,
providerId: account.providerId,
},
returnHeaders: false,