Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/external-account-id.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/backend': patch
---

Add `externalAccountId` to the backend `ExternalAccount` resource. This exposes the external account's `eac_`-prefixed id returned by `getUser()`, which is the id `users.deleteUserExternalAccount()` expects. Previously only the `idn_`-prefixed identification id was reachable through `id`, so deleting an external account fetched from `getUser()` failed with a 404.
6 changes: 6 additions & 0 deletions packages/backend/src/api/resources/ExternalAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export class ExternalAccount {
* The unique identifier for this external account.
*/
readonly id: string,
/**
* The unique identifier for the external account resource (prefixed with `eac_`).
* This is the value expected by methods such as `users.deleteUserExternalAccount()`.
*/
readonly externalAccountId: string,
/**
* The provider name (e.g., `google`).
*/
Expand Down Expand Up @@ -74,6 +79,7 @@ export class ExternalAccount {
static fromJSON(data: ExternalAccountJSON): ExternalAccount {
return new ExternalAccount(
data.id,
data.external_account_id,
data.provider,
data.provider_user_id,
data.identification_id,
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/api/resources/JSON.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ export interface EnterpriseAccountJSON extends ClerkResourceJSON {

export interface ExternalAccountJSON extends ClerkResourceJSON {
object: typeof ObjectType.ExternalAccount;
external_account_id: string;
provider: string;
identification_id: string;
provider_user_id: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { describe, expect, it } from 'vitest';

import { ExternalAccount } from '../ExternalAccount';
import type { ExternalAccountJSON } from '../JSON';

describe('ExternalAccount', () => {
describe('fromJSON', () => {
const data: ExternalAccountJSON = {
object: 'external_account',
id: 'idn_2ABXLLckIF5kLikvzAVRxuuN31M',
external_account_id: 'eac_2ABXLObDmeHsnLsLgOd5panvOPJ',
identification_id: 'idn_2ABXLLckIF5kLikvzAVRxuuN31M',
provider: 'oauth_google',
provider_user_id: '1029384756',
approved_scopes: 'email profile',
email_address: 'jane@example.com',
first_name: 'Jane',
last_name: 'Doe',
image_url: 'https://img.clerk.com/jane.png',
username: 'jane',
phone_number: null,
public_metadata: {},
label: null,
verification: null,
} as ExternalAccountJSON;

it('maps external_account_id to externalAccountId', () => {
const externalAccount = ExternalAccount.fromJSON(data);

expect(externalAccount.externalAccountId).toBe('eac_2ABXLObDmeHsnLsLgOd5panvOPJ');
});

it('keeps id and identificationId pointing at the identification id', () => {
const externalAccount = ExternalAccount.fromJSON(data);

expect(externalAccount.id).toBe('idn_2ABXLLckIF5kLikvzAVRxuuN31M');
expect(externalAccount.identificationId).toBe('idn_2ABXLLckIF5kLikvzAVRxuuN31M');
});
});
});