mirror of
https://github.com/better-auth/better-auth.git
synced 2026-10-19 11:24:57 -05:00
fix(account): use accountId instead of id in accountInfo endpoint (#8346)
Co-authored-by: Alex Yang <himself65@outlook.com>
This commit is contained in:
committed by
Alex Yang
co-authored by
Alex Yang
parent
e3bc6a2e5c
commit
efcc2384b4
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user