Skip to content

Commit 1a6bc52

Browse files
committed
Introduce localization key for enterprise SSO
1 parent 45d5918 commit 1a6bc52

39 files changed

+253
-31
lines changed

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

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
import { buildEmailLinkRedirectUrl, buildSSOCallbackURL } from '../redirects';
1+
import { buildSSOCallbackURL, buildVerificationRedirectUrl } from '../redirects';
22

3-
describe('buildEmailLinkRedirectUrl(routing, baseUrl)', () => {
3+
describe('buildVerificationRedirectUrl(routing, baseUrl)', () => {
44
it('defaults to hash based routing strategy on empty routing', function () {
5-
expect(buildEmailLinkRedirectUrl({ path: '', authQueryString: '' } as any, '')).toBe('http://localhost/#/verify');
5+
expect(buildVerificationRedirectUrl({ path: '', authQueryString: '' } as any, '')).toBe(
6+
'http://localhost/#/verify',
7+
);
68
});
79

810
it('returns the magic link redirect url for components using path based routing ', function () {
9-
expect(buildEmailLinkRedirectUrl({ routing: 'path', authQueryString: '' } as any, '')).toBe(
11+
expect(buildVerificationRedirectUrl({ routing: 'path', authQueryString: '' } as any, '')).toBe(
1012
'http://localhost/verify',
1113
);
1214

13-
expect(buildEmailLinkRedirectUrl({ routing: 'path', path: '/sign-in', authQueryString: '' } as any, '')).toBe(
15+
expect(buildVerificationRedirectUrl({ routing: 'path', path: '/sign-in', authQueryString: '' } as any, '')).toBe(
1416
'http://localhost/sign-in/verify',
1517
);
1618

1719
expect(
18-
buildEmailLinkRedirectUrl(
20+
buildVerificationRedirectUrl(
1921
{
2022
routing: 'path',
2123
path: '',
@@ -26,7 +28,7 @@ describe('buildEmailLinkRedirectUrl(routing, baseUrl)', () => {
2628
).toBe('http://localhost/verify?redirectUrl=https://clerk.com');
2729

2830
expect(
29-
buildEmailLinkRedirectUrl(
31+
buildVerificationRedirectUrl(
3032
{
3133
routing: 'path',
3234
path: '/sign-in',
@@ -37,7 +39,7 @@ describe('buildEmailLinkRedirectUrl(routing, baseUrl)', () => {
3739
).toBe('http://localhost/sign-in/verify?redirectUrl=https://clerk.com');
3840

3941
expect(
40-
buildEmailLinkRedirectUrl(
42+
buildVerificationRedirectUrl(
4143
{
4244
routing: 'path',
4345
path: '/sign-in',
@@ -50,7 +52,7 @@ describe('buildEmailLinkRedirectUrl(routing, baseUrl)', () => {
5052

5153
it('returns the magic link redirect url for components using hash based routing ', function () {
5254
expect(
53-
buildEmailLinkRedirectUrl(
55+
buildVerificationRedirectUrl(
5456
{
5557
routing: 'hash',
5658
authQueryString: '',
@@ -60,7 +62,7 @@ describe('buildEmailLinkRedirectUrl(routing, baseUrl)', () => {
6062
).toBe('http://localhost/#/verify');
6163

6264
expect(
63-
buildEmailLinkRedirectUrl(
65+
buildVerificationRedirectUrl(
6466
{
6567
routing: 'hash',
6668
path: '/sign-in',
@@ -71,7 +73,7 @@ describe('buildEmailLinkRedirectUrl(routing, baseUrl)', () => {
7173
).toBe('http://localhost/#/verify');
7274

7375
expect(
74-
buildEmailLinkRedirectUrl(
76+
buildVerificationRedirectUrl(
7577
{
7678
routing: 'hash',
7779
path: '',
@@ -82,7 +84,7 @@ describe('buildEmailLinkRedirectUrl(routing, baseUrl)', () => {
8284
).toBe('http://localhost/#/verify?redirectUrl=https://clerk.com');
8385

8486
expect(
85-
buildEmailLinkRedirectUrl(
87+
buildVerificationRedirectUrl(
8688
{
8789
routing: 'hash',
8890
path: '/sign-in',
@@ -93,7 +95,7 @@ describe('buildEmailLinkRedirectUrl(routing, baseUrl)', () => {
9395
).toBe('http://localhost/#/verify?redirectUrl=https://clerk.com');
9496

9597
expect(
96-
buildEmailLinkRedirectUrl(
98+
buildVerificationRedirectUrl(
9799
{
98100
routing: 'hash',
99101
path: '/sign-in',
@@ -106,7 +108,7 @@ describe('buildEmailLinkRedirectUrl(routing, baseUrl)', () => {
106108

107109
it('returns the magic link redirect url for components using virtual routing ', function () {
108110
expect(
109-
buildEmailLinkRedirectUrl(
111+
buildVerificationRedirectUrl(
110112
{
111113
routing: 'virtual',
112114
authQueryString: 'redirectUrl=https://clerk.com',
@@ -116,7 +118,7 @@ describe('buildEmailLinkRedirectUrl(routing, baseUrl)', () => {
116118
).toBe('https://accounts.clerk.com/sign-in#/verify?redirectUrl=https://clerk.com');
117119

118120
expect(
119-
buildEmailLinkRedirectUrl(
121+
buildVerificationRedirectUrl(
120122
{
121123
routing: 'virtual',
122124
} as any,

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

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export const EmailForm = withCardStateProvider((props: EmailFormProps) => {
2020
const card = useCardState();
2121
const { user } = useUser();
2222
const environment = useEnvironment();
23-
const preferEmailLinks = emailLinksEnabledForInstance(environment);
2423

2524
const [createEmailAddress] = useReverification(() => user?.createEmailAddress({ email: emailField.value }));
2625

@@ -53,15 +52,13 @@ export const EmailForm = withCardStateProvider((props: EmailFormProps) => {
5352
.catch(e => handleError(e, [emailField], card.setError));
5453
};
5554

55+
const translationKey = getTranslationKeyByStrategy(strategy);
56+
5657
return (
5758
<Wizard {...wizard.props}>
5859
<FormContainer
5960
headerTitle={localizationKeys('userProfile.emailAddressPage.title')}
60-
headerSubtitle={
61-
preferEmailLinks
62-
? localizationKeys('userProfile.emailAddressPage.emailLink.formHint')
63-
: localizationKeys('userProfile.emailAddressPage.emailCode.formHint')
64-
}
61+
headerSubtitle={localizationKeys(`${translationKey}.formHint`)}
6562
>
6663
<Form.Root onSubmit={addEmail}>
6764
<Form.ControlRow elementId={emailField.id}>
@@ -80,15 +77,9 @@ export const EmailForm = withCardStateProvider((props: EmailFormProps) => {
8077

8178
<FormContainer
8279
headerTitle={localizationKeys('userProfile.emailAddressPage.verifyTitle')}
83-
headerSubtitle={
84-
strategy === 'enterprise_sso' || preferEmailLinks
85-
? localizationKeys('userProfile.emailAddressPage.emailLink.formSubtitle', {
86-
identifier: emailAddressRef.current?.emailAddress,
87-
})
88-
: localizationKeys('userProfile.emailAddressPage.emailCode.formSubtitle', {
89-
identifier: emailAddressRef.current?.emailAddress,
90-
})
91-
}
80+
headerSubtitle={localizationKeys(`${translationKey}.formSubtitle`, {
81+
identifier: emailAddressRef.current?.emailAddress,
82+
})}
9283
>
9384
{strategy === 'email_link' && (
9485
<VerifyWithLink
@@ -118,6 +109,19 @@ export const EmailForm = withCardStateProvider((props: EmailFormProps) => {
118109
);
119110
});
120111

112+
const getTranslationKeyByStrategy = (strategy: PrepareEmailAddressVerificationParams['strategy']) => {
113+
switch (strategy) {
114+
case 'email_code':
115+
return 'userProfile.emailAddressPage.emailLink';
116+
case 'enterprise_sso':
117+
return 'userProfile.emailAddressPage.enterpriseSsoLink';
118+
case 'email_link':
119+
return 'userProfile.emailAddressPage.emailLink';
120+
default:
121+
throw new Error(`Unsupported strategy for email verification: ${strategy}`);
122+
}
123+
};
124+
121125
function emailLinksEnabledForInstance(env: EnvironmentResource): boolean {
122126
const { userSettings } = env;
123127
const { email_address } = userSettings.attributes;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const VerifyWithEnterpriseConnection = (props: VerifyWithEnterpriseConnec
4545
return (
4646
<>
4747
<VerificationLink
48-
resendButton={localizationKeys('userProfile.emailAddressPage.emailLink.resendButton')}
48+
resendButton={localizationKeys('userProfile.emailAddressPage.enterpriseSsoLink.resendButton')}
4949
onResendCodeClicked={startVerification}
5050
/>
5151
<FormButtonContainer>

packages/localizations/src/ar-SA.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,12 @@ export const arSA: LocalizationResource = {
692692
resendButton: 'لم يصلك الرابط؟ حاول مرة أخرى',
693693
successMessage: 'البريد الإلكتروني {{identifier}} تمت إضافته إلى حسابك',
694694
},
695+
enterpriseSsoLink: {
696+
formHint: undefined,
697+
formSubtitle: undefined,
698+
resendButton: undefined,
699+
successMessage: undefined,
700+
},
695701
removeResource: {
696702
messageLine1: 'سيتم حذف هذا الإيميل من حسابك {{identifier}}',
697703
messageLine2: 'لن تتمكن من تسجيل الدخول باستخدام عنوان البريد الإلكتروني هذا.',

packages/localizations/src/be-BY.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,12 @@ export const beBY: LocalizationResource = {
699699
resendButton: 'Адправіць спасылку паўторна',
700700
successMessage: 'Адрас электроннай пошты {{identifier}} быў дададзены ў ваш уліковы запіс.',
701701
},
702+
enterpriseSsoLink: {
703+
formHint: undefined,
704+
formSubtitle: undefined,
705+
resendButton: undefined,
706+
successMessage: undefined,
707+
},
702708
removeResource: {
703709
messageLine1: '{{identifier}} будзе выдалены з гэтага ўліковага запісу.',
704710
messageLine2: 'Вы больш не зможаце ўваходзіць, выкарыстоўваючы гэты адрас электроннай пошты.',

packages/localizations/src/bg-BG.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,12 @@ export const bgBG: LocalizationResource = {
694694
resendButton: 'Не сте получили линк? Изпрати отново',
695695
successMessage: 'Имейлът {{identifier}} беше добавен към вашия профил.',
696696
},
697+
enterpriseSsoLink: {
698+
formHint: undefined,
699+
formSubtitle: undefined,
700+
resendButton: undefined,
701+
successMessage: undefined,
702+
},
697703
removeResource: {
698704
messageLine1: '{{identifier}} ще бъде премахнат от този профил.',
699705
messageLine2: 'Няма да можете да влезете в профила си, използвайки този имейл адрес.',

packages/localizations/src/cs-CZ.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,12 @@ export const csCZ: LocalizationResource = {
691691
resendButton: 'Znovu odeslat odkaz',
692692
successMessage: 'E-mailová adresa {{identifier}} byla přidána k vašemu účtu.',
693693
},
694+
enterpriseSsoLink: {
695+
formHint: undefined,
696+
formSubtitle: undefined,
697+
resendButton: undefined,
698+
successMessage: undefined,
699+
},
694700
removeResource: {
695701
messageLine1: '{{identifier}} bude odstraněna z tohoto účtu.',
696702
messageLine2: 'Nebudete se moci přihlásit pomocí této e-mailové adresy.',

packages/localizations/src/da-DK.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,12 @@ export const daDK: LocalizationResource = {
693693
resendButton: 'Send link igen',
694694
successMessage: 'E-mailen {{identifier}} er blevet tilføjet til din konto.',
695695
},
696+
enterpriseSsoLink: {
697+
formHint: undefined,
698+
formSubtitle: undefined,
699+
resendButton: undefined,
700+
successMessage: undefined,
701+
},
696702
removeResource: {
697703
messageLine1: '{{identifier}} vil blive fjernet fra denne konto.',
698704
messageLine2: 'Du vil ikke længere kunne logge ind med denne e-mailadresse.',

packages/localizations/src/de-DE.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,12 @@ export const deDE: LocalizationResource = {
706706
resendButton: 'Link erneut senden',
707707
successMessage: 'Die E-Mail-Adresse {{identifier}} wurde Ihrem Konto hinzugefügt.',
708708
},
709+
enterpriseSsoLink: {
710+
formHint: undefined,
711+
formSubtitle: undefined,
712+
resendButton: undefined,
713+
successMessage: undefined,
714+
},
709715
removeResource: {
710716
messageLine1: '{{identifier}} wird aus diesem Konto entfernt.',
711717
messageLine2: 'Sie können sich nicht mehr mit dieser E-Mail-Adresse anmelden.',

packages/localizations/src/el-GR.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,12 @@ export const elGR: LocalizationResource = {
700700
resendButton: 'Δεν λάβατε κάποιον σύνδεσμο; Επανάληψη αποστολής',
701701
successMessage: 'Το email {{identifier}} έχει προστεθεί στον λογαριασμό σας.',
702702
},
703+
enterpriseSsoLink: {
704+
formHint: undefined,
705+
formSubtitle: undefined,
706+
resendButton: undefined,
707+
successMessage: undefined,
708+
},
703709
removeResource: {
704710
messageLine1: 'Η διεύθυνση {{identifier}} θα αφαιρεθεί από αυτόν τον λογαριασμό.',
705711
messageLine2: 'Δεν θα μπορείτε πλέον να συνδεθείτε χρησιμοποιώντας αυτήν τη διεύθυνση email.',

0 commit comments

Comments
 (0)