Skip to content

Commit

Permalink
Merge pull request #81 from clerkinc/external-account-new-properties
Browse files Browse the repository at this point in the history
feat(types,backend-core,clerk-js): Add external account properties username, publicMetadata & label
  • Loading branch information
chanioxaris authored Mar 8, 2022
2 parents 3c0724a + 53d0020 commit 61c68c1
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/backend-core/src/__tests__/apis/UserApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,13 @@ test('getUser() returns a single user', async () => {

expect(user.externalAccounts.length).toEqual(2);
expect(user.externalAccounts[0].provider).toEqual('google');
expect(user.externalAccounts[0].username).toEqual('tester');
expect(user.externalAccounts[0].publicMetadata).toBeInstanceOf(Object);
expect(user.externalAccounts[0].label).toBeNull();
expect(user.externalAccounts[1].provider).toEqual('facebook');
expect(user.externalAccounts[1].username).toBeNull();
expect(user.externalAccounts[1].publicMetadata).toMatchObject({'extra': 'more info'});
expect(user.externalAccounts[1].label).toEqual('clerk');

expect(user.web3Wallets.length).toEqual(1);
expect(user.web3Wallets[0].web3Wallet).toEqual(
Expand Down
12 changes: 10 additions & 2 deletions packages/backend-core/src/__tests__/apis/responses/getUser.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@
"email_address": "kyle@tech.com",
"given_name": "Kyle",
"family_name": "Reese",
"picture": "https://lh3.googleusercontent.com/-MvTefx9nU6o/BBBBBBBBBBI/BBBBBBBBBBB/ereRAMWiew8hQ5IaSVdTZWm1Y1G1z0T_P7Q/s96-c/photo.jpg"
"picture": "https://lh3.googleusercontent.com/-MvTefx9nU6o/BBBBBBBBBBI/BBBBBBBBBBB/ereRAMWiew8hQ5IaSVdTZWm1Y1G1z0T_P7Q/s96-c/photo.jpg",
"username": "tester",
"public_metadata": {},
"label": null
},
{
"object": "facebook_account",
Expand All @@ -101,7 +104,12 @@
"email_address": "kyle@tech.com",
"first_name": "Kyle",
"last_name": "Reese",
"picture": "https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=16357923188267094&height=50&width=50&ext=2319847405&hash=AeQyoXRpxMMso8vNHSw"
"picture": "https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=16357923188267094&height=50&width=50&ext=2319847405&hash=AeQyoXRpxMMso8vNHSw",
"username": null,
"public_metadata": {
"extra": "more info"
},
"label": "clerk"
}
],
"public_metadata": {
Expand Down
6 changes: 6 additions & 0 deletions packages/backend-core/src/api/resources/ExternalAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export class ExternalAccount {
'firstName',
'lastName',
'picture',
'username',
'publicMetadata',
'label',
];

static defaults = {};
Expand All @@ -30,6 +33,9 @@ export class ExternalAccount {
obj.id = data.id;
obj.approvedScopes = data.approved_scopes;
obj.emailAddress = data.email_address;
obj.username = data.username;
obj.publicMetadata = data.public_metadata;
obj.label = data.label;

switch (data.object) {
case ObjectType.FacebookAccount: {
Expand Down
9 changes: 9 additions & 0 deletions packages/backend-core/src/api/resources/JSON.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ export interface FacebookAccountJSON extends ClerkResourceJSON {
first_name: string;
last_name: string;
picture: string;
username?: string;
public_metadata: Record<string, unknown>;
label?: string;
}

export interface GoogleAccountJSON extends ClerkResourceJSON {
Expand All @@ -84,6 +87,9 @@ export interface GoogleAccountJSON extends ClerkResourceJSON {
given_name: string;
family_name: string;
picture: string;
username?: string;
public_metadata: Record<string, unknown>;
label?: string;
}

export interface ExtAccountJSON extends ClerkResourceJSON {
Expand All @@ -96,6 +102,9 @@ export interface ExtAccountJSON extends ClerkResourceJSON {
first_name: string;
last_name: string;
avatar_url: string;
username?: string;
public_metadata: Record<string, unknown>;
label?: string;
}

export type ExternalAccountJSON =
Expand Down
3 changes: 3 additions & 0 deletions packages/backend-core/src/api/resources/Props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export interface ExternalAccountProps extends ClerkProps {
firstName: Nullable<string>;
lastName: Nullable<string>;
picture: Nullable<string>;
username: Nullable<string>;
publicMetadata: Record<string, unknown>;
label: Nullable<string>;
}

export interface IdentificationLinkProps extends ClerkProps {
Expand Down
9 changes: 9 additions & 0 deletions packages/clerk-js/src/core/resources/ExternalAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export class ExternalAccount implements ExternalAccountResource {
firstName: string;
lastName: string;
picture: string;
username?: string;
publicMetadata: Record<string, unknown>;
label?: string;

constructor(extAccProps: ExternalAccountResource) {
this.id = extAccProps.id;
Expand All @@ -24,6 +27,9 @@ export class ExternalAccount implements ExternalAccountResource {
this.firstName = extAccProps.firstName;
this.lastName = extAccProps.lastName;
this.picture = extAccProps.picture;
this.username = extAccProps.username;
this.publicMetadata = extAccProps.publicMetadata;
this.label = extAccProps.label;
}

static fromJSON(data: ExternalAccountJSON): ExternalAccount {
Expand Down Expand Up @@ -66,6 +72,9 @@ export class ExternalAccount implements ExternalAccountResource {
// ${provider}_id key in order to set the externalId.
// @ts-ignore
obj.externalId = data.provider_user_id || data[`${obj.provider}_id`];
obj.username = data.username;
obj.publicMetadata = data.public_metadata;
obj.label = data.label;

return new ExternalAccount(obj);
}
Expand Down
3 changes: 3 additions & 0 deletions packages/types/src/externalAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export interface ExternalAccountResource {
firstName: string;
lastName: string;
picture: string;
username?: string;
publicMetadata: Record<string, unknown>;
label?: string;

providerTitle: () => string;
}
9 changes: 9 additions & 0 deletions packages/types/src/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ export type ExternalAccountJSON =
given_name: string;
family_name: string;
picture: string;
username?: string;
public_metadata: Record<string, unknown>;
label?: string;
}
| {
object: 'facebook_account';
Expand All @@ -308,6 +311,9 @@ export type ExternalAccountJSON =
first_name: string;
last_name: string;
picture: string;
username?: string;
public_metadata: Record<string, unknown>;
label?: string;
}
| {
object: 'external_account';
Expand All @@ -319,6 +325,9 @@ export type ExternalAccountJSON =
first_name: string;
last_name: string;
avatar_url: string;
username?: string;
public_metadata: Record<string, unknown>;
label?: string;
};

export interface OrganizationJSON extends ClerkResourceJSON {
Expand Down

0 comments on commit 61c68c1

Please sign in to comment.