Skip to content

Commit 0d9bdfe

Browse files
committed
Rename verification hook to enterprise SSO
1 parent 9471486 commit 0d9bdfe

File tree

13 files changed

+74
-75
lines changed

13 files changed

+74
-75
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,21 @@ export class EmailAddress extends BaseResource implements EmailAddressResource {
8080
return { startEmailLinkFlow, cancelEmailLinkFlow: stop };
8181
};
8282

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

89-
const startEnterpriseConnectionLinkFlow = async ({
89+
const startEnterpriseSsoLinkFlow = async ({
9090
redirectUrl,
9191
}: StartEnterpriseConnectionLinkFlowParams): Promise<EmailAddressResource> => {
9292
if (!this.id) {
9393
clerkVerifyEmailAddressCalledBeforeCreate('SignUp');
9494
}
9595
const response = await this.prepareVerification({
9696
strategy: 'enterprise_sso',
97-
redirectUrl: redirectUrl,
97+
redirectUrl,
9898
});
9999
if (!response.verification.externalVerificationRedirectURL) {
100100
throw Error('Unexpected: External verification redirect URL is missing');
@@ -116,7 +116,7 @@ export class EmailAddress extends BaseResource implements EmailAddressResource {
116116
});
117117
});
118118
};
119-
return { startEnterpriseConnectionLinkFlow, cancelEnterpriseConnectionLinkFlow: stop };
119+
return { startEnterpriseSsoLinkFlow, cancelEnterpriseSsoLinkFlow: stop };
120120
};
121121

122122
destroy = (): Promise<void> => this._baseDelete();

packages/clerk-js/src/ui/common/redirects.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { buildURL } from '../../utils/url';
22
import type { SignInContextType, SignUpContextType, UserProfileContextType } from './../contexts';
33

44
const SSO_CALLBACK_PATH_ROUTE = '/sso-callback';
5-
const MAGIC_LINK_VERIFY_PATH_ROUTE = '/verify';
5+
const VERIFICATION_PATH_ROUTE = '/verify';
66

7-
export function buildEmailLinkRedirectUrl(
7+
export function buildVerificationRedirectUrl(
88
ctx: SignInContextType | SignUpContextType | UserProfileContextType,
99
baseUrl: string | undefined = '',
1010
): string {
@@ -14,7 +14,7 @@ export function buildEmailLinkRedirectUrl(
1414
baseUrl,
1515
authQueryString,
1616
path,
17-
endpoint: MAGIC_LINK_VERIFY_PATH_ROUTE,
17+
endpoint: VERIFICATION_PATH_ROUTE,
1818
});
1919
}
2020

packages/clerk-js/src/ui/components/SignIn/SignInFactorOneEmailLinkCard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { EmailLinkFactor, SignInResource } from '@clerk/types';
44
import React from 'react';
55

66
import { EmailLinkStatusCard } from '../../common';
7-
import { buildEmailLinkRedirectUrl } from '../../common/redirects';
7+
import { buildVerificationRedirectUrl } from '../../common/redirects';
88
import { useCoreSignIn, useSignInContext } from '../../contexts';
99
import { Flow, localizationKeys, useLocalizations } from '../../customizables';
1010
import type { VerificationCodeCardProps } from '../../elements';
@@ -45,7 +45,7 @@ export const SignInFactorOneEmailLinkCard = (props: SignInFactorOneEmailLinkCard
4545
const startEmailLinkVerification = () => {
4646
startEmailLinkFlow({
4747
emailAddressId: props.factor.emailAddressId,
48-
redirectUrl: buildEmailLinkRedirectUrl(signInContext, signInUrl),
48+
redirectUrl: buildVerificationRedirectUrl(signInContext, signInUrl),
4949
})
5050
.then(res => handleVerificationResult(res))
5151
.catch(err => {

packages/clerk-js/src/ui/components/SignUp/SignUpEmailLinkCard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { SignUpResource } from '@clerk/types';
33
import React from 'react';
44

55
import { EmailLinkStatusCard } from '../../common';
6-
import { buildEmailLinkRedirectUrl } from '../../common/redirects';
6+
import { buildVerificationRedirectUrl } from '../../common/redirects';
77
import { useCoreSignUp, useEnvironment, useSignUpContext } from '../../contexts';
88
import { Flow, localizationKeys, useLocalizations } from '../../customizables';
99
import { VerificationLinkCard } from '../../elements';
@@ -36,7 +36,7 @@ export const SignUpEmailLinkCard = () => {
3636
};
3737

3838
const startEmailLinkVerification = () => {
39-
return startEmailLinkFlow({ redirectUrl: buildEmailLinkRedirectUrl(signUpContext, displayConfig.signUpUrl) })
39+
return startEmailLinkFlow({ redirectUrl: buildVerificationRedirectUrl(signUpContext, displayConfig.signUpUrl) })
4040
.then(res => handleVerificationResult(res))
4141
.catch(err => {
4242
handleError(err, [], card.setError);

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

Lines changed: 17 additions & 4 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 } from '@clerk/types';
2+
import type { EmailAddressResource, PrepareEmailAddressVerificationParams } from '@clerk/types';
33
import React from 'react';
44

55
import { useWizard, Wizard } from '../../common';
@@ -8,7 +8,7 @@ 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, getVerificationStrategy } from './utils';
11+
import { emailLinksEnabledForInstance } from './utils';
1212
import { VerifyWithCode } from './VerifyWithCode';
1313
import { VerifyWithEnterpriseConnection } from './VerifyWithEnterpriseConnection';
1414
import { VerifyWithLink } from './VerifyWithLink';
@@ -24,7 +24,7 @@ export const EmailForm = withCardStateProvider((props: EmailFormProps) => {
2424
const preferEmailLinks = emailLinksEnabledForInstance(environment);
2525
const [createEmailAddress] = useReverification(() => user?.createEmailAddress({ email: emailField.value }));
2626
const emailAddressRef = React.useRef<EmailAddressResource | undefined>(user?.emailAddresses.find(a => a.id === id));
27-
const strategy = getVerificationStrategy(emailAddressRef.current, preferEmailLinks);
27+
const strategy = getEmailAddressVerificationStrategy(emailAddressRef.current, preferEmailLinks);
2828
const wizard = useWizard({
2929
defaultStep: emailAddressRef.current ? 1 : 0,
3030
onNextStep: () => card.setError(undefined),
@@ -80,6 +80,7 @@ export const EmailForm = withCardStateProvider((props: EmailFormProps) => {
8080
<FormContainer
8181
headerTitle={localizationKeys('userProfile.emailAddressPage.verifyTitle')}
8282
headerSubtitle={
83+
// TODO - Get localization per strategy
8384
preferEmailLinks
8485
? localizationKeys('userProfile.emailAddressPage.emailLink.formSubtitle', {
8586
identifier: emailAddressRef.current?.emailAddress,
@@ -105,7 +106,7 @@ export const EmailForm = withCardStateProvider((props: EmailFormProps) => {
105106
onReset={onReset}
106107
/>
107108
)}
108-
{strategy === 'saml' && (
109+
{strategy === 'enterprise_sso' && (
109110
<VerifyWithEnterpriseConnection
110111
nextStep={onSuccess}
111112
email={emailAddressRef.current as any}
@@ -116,3 +117,15 @@ export const EmailForm = withCardStateProvider((props: EmailFormProps) => {
116117
</Wizard>
117118
);
118119
});
120+
121+
// TODO - Handle `preferEmailLinks`
122+
export const getEmailAddressVerificationStrategy = (
123+
emailAddress: EmailAddressResource | undefined,
124+
preferLinks: boolean,
125+
): PrepareEmailAddressVerificationParams['strategy'] => {
126+
if (emailAddress?.matchesEnterpriseConnection) {
127+
return 'enterprise_sso';
128+
}
129+
130+
return preferLinks ? 'email_link' : 'email_code';
131+
};

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import type { EmailAddressResource } from '@clerk/types';
22
import React from 'react';
33

44
import { EmailLinkStatusCard } from '../../common';
5-
import { buildEmailLinkRedirectUrl } from '../../common/redirects';
5+
import { buildVerificationRedirectUrl } from '../../common/redirects';
66
import { useEnvironment, useUserProfileContext } from '../../contexts';
77
import { Button, descriptors, localizationKeys } from '../../customizables';
88
import { FormButtonContainer, useCardState, VerificationLink } from '../../elements';
9-
import { useEnterpriseConnectionLink } from '../../hooks';
9+
import { useEnterpriseSsoLink } from '../../hooks';
1010
import { handleError } from '../../utils';
1111

1212
type VerifyWithEnterpriseConnectionProps = {
@@ -19,7 +19,7 @@ export const VerifyWithEnterpriseConnection = (props: VerifyWithEnterpriseConnec
1919
const { email, nextStep, onReset } = props;
2020
const card = useCardState();
2121
const profileContext = useUserProfileContext();
22-
const { startEnterpriseConnectionLinkFlow } = useEnterpriseConnectionLink(email);
22+
const { startEnterpriseSsoLinkFlow } = useEnterpriseSsoLink(email);
2323
const { displayConfig } = useEnvironment();
2424

2525
React.useEffect(() => {
@@ -36,14 +36,15 @@ export const VerifyWithEnterpriseConnection = (props: VerifyWithEnterpriseConnec
3636
*/
3737
const { routing } = profileContext;
3838
const baseUrl = routing === 'virtual' ? displayConfig.userProfileUrl : '';
39-
const redirectUrl = buildEmailLinkRedirectUrl(profileContext, baseUrl);
40-
startEnterpriseConnectionLinkFlow({ redirectUrl })
39+
const redirectUrl = buildVerificationRedirectUrl(profileContext, baseUrl);
40+
startEnterpriseSsoLinkFlow({ redirectUrl })
4141
.then(() => nextStep())
4242
.catch(err => handleError(err, [], card.setError));
4343
}
4444

4545
return (
4646
<>
47+
{/* TODO - Handle localization */}
4748
<VerificationLink
4849
resendButton={localizationKeys('userProfile.emailAddressPage.emailLink.resendButton')}
4950
onResendCodeClicked={startVerification}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { EmailAddressResource } from '@clerk/types';
22
import React from 'react';
33

44
import { EmailLinkStatusCard } from '../../common';
5-
import { buildEmailLinkRedirectUrl } from '../../common/redirects';
5+
import { buildVerificationRedirectUrl } from '../../common/redirects';
66
import { useEnvironment, useUserProfileContext } from '../../contexts';
77
import { Button, descriptors, localizationKeys } from '../../customizables';
88
import { FormButtonContainer, useCardState, VerificationLink } from '../../elements';
@@ -37,7 +37,7 @@ export const VerifyWithLink = (props: VerifyWithLinkProps) => {
3737
const { routing } = profileContext;
3838
const baseUrl = routing === 'virtual' ? displayConfig.userProfileUrl : '';
3939

40-
const redirectUrl = buildEmailLinkRedirectUrl(profileContext, baseUrl);
40+
const redirectUrl = buildVerificationRedirectUrl(profileContext, baseUrl);
4141
startEmailLinkFlow({ redirectUrl })
4242
.then(() => nextStep())
4343
.catch(err => handleError(err, [], card.setError));

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type {
33
EmailAddressResource,
44
EnvironmentResource,
55
PhoneNumberResource,
6-
PrepareEmailAddressVerificationParams,
76
UserResource,
87
} from '@clerk/types';
98

@@ -77,14 +76,3 @@ export function sortIdentificationBasedOnVerification<T extends Array<EmailAddre
7776

7877
return [...primaryItem, ...verifiedItems, ...unverifiedItems, ...unverifiedItemsWithoutVerification] as T;
7978
}
80-
81-
export const getVerificationStrategy = (
82-
emailAddress: EmailAddressResource | undefined,
83-
preferLinks: boolean,
84-
): PrepareEmailAddressVerificationParams['strategy'] => {
85-
if (emailAddress?.matchesEnterpriseConnection) {
86-
return 'saml';
87-
}
88-
89-
return preferLinks ? 'email_link' : 'email_code';
90-
};

packages/clerk-js/src/ui/hooks/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ export * from './useDebounce';
1818
export * from './useScrollLock';
1919
export * from './useClerkModalStateParams';
2020
export * from './useNavigateToFlowStart';
21-
export * from './useEnterpriseConnectionLink';
21+
export * from './useEnterpriseSsoLink';

packages/clerk-js/src/ui/hooks/useEnterpriseConnectionLink.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)