Skip to content

Commit ccd2711

Browse files
committed
Rename matchesEnterpriseConnection to hasEnterpriseSso
1 parent 7ed4e28 commit ccd2711

File tree

6 files changed

+27
-35
lines changed

6 files changed

+27
-35
lines changed

packages/clerk-js/src/core/resources/EmailAddress.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { Poller } from '@clerk/shared/poller';
22
import type {
33
AttemptEmailAddressVerificationParams,
44
CreateEmailLinkFlowReturn,
5-
CreateEnterpriseConnectionLinkFlowReturn,
5+
CreateEnterpriseSsoLinkFlowReturn,
66
EmailAddressJSON,
77
EmailAddressResource,
88
IdentificationLinkResource,
99
PrepareEmailAddressVerificationParams,
1010
StartEmailLinkFlowParams,
11-
StartEnterpriseConnectionLinkFlowParams,
11+
StartEnterpriseSsoLinkFlowParams,
1212
VerificationResource,
1313
} from '@clerk/types';
1414

@@ -18,7 +18,7 @@ import { BaseResource, IdentificationLink, Verification } from './internal';
1818
export class EmailAddress extends BaseResource implements EmailAddressResource {
1919
id!: string;
2020
emailAddress = '';
21-
matchesEnterpriseConnection = false;
21+
hasEnterpriseSso = false;
2222
linkedTo: IdentificationLinkResource[] = [];
2323
verification!: VerificationResource;
2424

@@ -80,15 +80,15 @@ export class EmailAddress extends BaseResource implements EmailAddressResource {
8080
return { startEmailLinkFlow, cancelEmailLinkFlow: stop };
8181
};
8282

83-
createEnterpriseSsoLinkFlow = (): CreateEnterpriseConnectionLinkFlowReturn<
84-
StartEnterpriseConnectionLinkFlowParams,
83+
createEnterpriseSsoLinkFlow = (): CreateEnterpriseSsoLinkFlowReturn<
84+
StartEnterpriseSsoLinkFlowParams,
8585
EmailAddressResource
8686
> => {
8787
const { run, stop } = Poller();
8888

8989
const startEnterpriseSsoLinkFlow = async ({
9090
redirectUrl,
91-
}: StartEnterpriseConnectionLinkFlowParams): Promise<EmailAddressResource> => {
91+
}: StartEnterpriseSsoLinkFlowParams): Promise<EmailAddressResource> => {
9292
if (!this.id) {
9393
clerkVerifyEmailAddressCalledBeforeCreate('SignUp');
9494
}
@@ -131,7 +131,7 @@ export class EmailAddress extends BaseResource implements EmailAddressResource {
131131
this.id = data.id;
132132
this.emailAddress = data.email_address;
133133
this.verification = new Verification(data.verification);
134-
this.matchesEnterpriseConnection = data.matches_enterprise_connection;
134+
this.hasEnterpriseSso = data.has_enterprise_sso;
135135
this.linkedTo = (data.linked_to || []).map(link => new IdentificationLink(link));
136136
return this;
137137
}

packages/clerk-js/src/ui/components/UserProfile/EmailForm.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useReverification, useUser } from '@clerk/shared/react';
2-
import type { EmailAddressResource, PrepareEmailAddressVerificationParams } from '@clerk/types';
2+
import type { EmailAddressResource, EnvironmentResource, PrepareEmailAddressVerificationParams } from '@clerk/types';
33
import React from 'react';
44

55
import { useWizard, Wizard } from '../../common';
@@ -8,7 +8,6 @@ import { localizationKeys } from '../../customizables';
88
import type { FormProps } from '../../elements';
99
import { Form, FormButtons, FormContainer, useCardState, withCardStateProvider } from '../../elements';
1010
import { handleError, useFormControl } from '../../utils';
11-
import { emailLinksEnabledForInstance } from './utils';
1211
import { VerifyWithCode } from './VerifyWithCode';
1312
import { VerifyWithEnterpriseConnection } from './VerifyWithEnterpriseConnection';
1413
import { VerifyWithLink } from './VerifyWithLink';
@@ -22,9 +21,11 @@ export const EmailForm = withCardStateProvider((props: EmailFormProps) => {
2221
const { user } = useUser();
2322
const environment = useEnvironment();
2423
const preferEmailLinks = emailLinksEnabledForInstance(environment);
24+
2525
const [createEmailAddress] = useReverification(() => user?.createEmailAddress({ email: emailField.value }));
26+
2627
const emailAddressRef = React.useRef<EmailAddressResource | undefined>(user?.emailAddresses.find(a => a.id === id));
27-
const strategy = getEmailAddressVerificationStrategy(emailAddressRef.current, preferEmailLinks);
28+
const strategy = getEmailAddressVerificationStrategy(emailAddressRef.current, environment);
2829
const wizard = useWizard({
2930
defaultStep: emailAddressRef.current ? 1 : 0,
3031
onNextStep: () => card.setError(undefined),
@@ -80,8 +81,7 @@ export const EmailForm = withCardStateProvider((props: EmailFormProps) => {
8081
<FormContainer
8182
headerTitle={localizationKeys('userProfile.emailAddressPage.verifyTitle')}
8283
headerSubtitle={
83-
// TODO - Get localization per strategy
84-
preferEmailLinks
84+
strategy === 'enterprise_sso' || preferEmailLinks
8585
? localizationKeys('userProfile.emailAddressPage.emailLink.formSubtitle', {
8686
identifier: emailAddressRef.current?.emailAddress,
8787
})
@@ -118,14 +118,19 @@ export const EmailForm = withCardStateProvider((props: EmailFormProps) => {
118118
);
119119
});
120120

121-
// TODO - Handle `preferEmailLinks`
122-
export const getEmailAddressVerificationStrategy = (
121+
function emailLinksEnabledForInstance(env: EnvironmentResource): boolean {
122+
const { userSettings } = env;
123+
const { email_address } = userSettings.attributes;
124+
return email_address.enabled && email_address.verifications.includes('email_link');
125+
}
126+
127+
const getEmailAddressVerificationStrategy = (
123128
emailAddress: EmailAddressResource | undefined,
124-
preferLinks: boolean,
129+
env: EnvironmentResource,
125130
): PrepareEmailAddressVerificationParams['strategy'] => {
126-
if (emailAddress?.matchesEnterpriseConnection) {
131+
if (emailAddress?.hasEnterpriseSso) {
127132
return 'enterprise_sso';
128133
}
129134

130-
return preferLinks ? 'email_link' : 'email_code';
135+
return emailLinksEnabledForInstance(env) ? 'email_link' : 'email_code';
131136
};

packages/clerk-js/src/ui/components/UserProfile/VerifyWithEnterpriseConnection.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export const VerifyWithEnterpriseConnection = (props: VerifyWithEnterpriseConnec
4444

4545
return (
4646
<>
47-
{/* TODO - Handle localization */}
4847
<VerificationLink
4948
resendButton={localizationKeys('userProfile.emailAddressPage.emailLink.resendButton')}
5049
onResendCodeClicked={startVerification}

packages/clerk-js/src/ui/components/UserProfile/utils.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import type {
2-
Attributes,
3-
EmailAddressResource,
4-
EnvironmentResource,
5-
PhoneNumberResource,
6-
UserResource,
7-
} from '@clerk/types';
1+
import type { Attributes, EmailAddressResource, PhoneNumberResource, UserResource } from '@clerk/types';
82

93
type IDable = { id: string };
104

@@ -16,12 +10,6 @@ export const currentSessionFirst = (id: string) => (a: IDable) => (a.id === id ?
1610

1711
export const defaultFirst = (a: PhoneNumberResource) => (a.defaultSecondFactor ? -1 : 1);
1812

19-
export function emailLinksEnabledForInstance(env: EnvironmentResource): boolean {
20-
const { userSettings } = env;
21-
const { email_address } = userSettings.attributes;
22-
return email_address.enabled && email_address.verifications.includes('email_link');
23-
}
24-
2513
export function getSecondFactors(attributes: Attributes): string[] {
2614
const secondFactors: string[] = [];
2715

packages/types/src/emailAddress.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { ClerkResource } from './resource';
33
import type { EmailCodeStrategy, EmailLinkStrategy, EnterpriseSSOStrategy } from './strategies';
44
import type {
55
CreateEmailLinkFlowReturn,
6-
CreateEnterpriseSsoFlowReturn,
6+
CreateEnterpriseSsoLinkFlowReturn,
77
StartEmailLinkFlowParams,
88
StartEnterpriseSsoLinkFlowParams,
99
VerificationResource,
@@ -30,13 +30,13 @@ export interface EmailAddressResource extends ClerkResource {
3030
id: string;
3131
emailAddress: string;
3232
verification: VerificationResource;
33-
matchesEnterpriseConnection: boolean;
33+
hasEnterpriseSso: boolean;
3434
linkedTo: IdentificationLinkResource[];
3535
toString: () => string;
3636
prepareVerification: (params: PrepareEmailAddressVerificationParams) => Promise<EmailAddressResource>;
3737
attemptVerification: (params: AttemptEmailAddressVerificationParams) => Promise<EmailAddressResource>;
3838
createEmailLinkFlow: () => CreateEmailLinkFlowReturn<StartEmailLinkFlowParams, EmailAddressResource>;
39-
createEnterpriseSsoLinkFlow: () => CreateEnterpriseSsoFlowReturn<
39+
createEnterpriseSsoLinkFlow: () => CreateEnterpriseSsoLinkFlowReturn<
4040
StartEnterpriseSsoLinkFlowParams,
4141
EmailAddressResource
4242
>;

packages/types/src/verification.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export interface StartEnterpriseSsoLinkFlowParams {
4646
redirectUrl: string;
4747
}
4848

49-
export type CreateEnterpriseSsoFlowReturn<Params, Resource> = {
49+
export type CreateEnterpriseSsoLinkFlowReturn<Params, Resource> = {
5050
startEnterpriseSsoLinkFlow: (params: Params) => Promise<Resource>;
5151
cancelEnterpriseSsoLinkFlow: () => void;
5252
};

0 commit comments

Comments
 (0)