-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d923c1
commit c701b85
Showing
11 changed files
with
206 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
packages/clerk-js/src/ui/components/UserProfile/VerifyWithEnterpriseConnection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import type { EmailAddressResource } from '@clerk/types'; | ||
import React from 'react'; | ||
|
||
import { EmailLinkStatusCard } from '../../common'; | ||
import { buildEmailLinkRedirectUrl } from '../../common/redirects'; | ||
import { useEnvironment, useUserProfileContext } from '../../contexts'; | ||
import { Button, descriptors, localizationKeys } from '../../customizables'; | ||
import { FormButtonContainer, useCardState, VerificationLink } from '../../elements'; | ||
import { useEnterpriseConnectionLink } from '../../hooks'; | ||
import { handleError } from '../../utils'; | ||
|
||
type VerifyWithEnterpriseConnectionProps = { | ||
email: EmailAddressResource; | ||
onReset: () => void; | ||
nextStep: () => void; | ||
}; | ||
|
||
export const VerifyWithEnterpriseConnection = (props: VerifyWithEnterpriseConnectionProps) => { | ||
const { email, nextStep, onReset } = props; | ||
const card = useCardState(); | ||
const profileContext = useUserProfileContext(); | ||
const { startEnterpriseConnectionLinkFlow } = useEnterpriseConnectionLink(email); | ||
const { displayConfig } = useEnvironment(); | ||
|
||
React.useEffect(() => { | ||
startVerification(); | ||
}, []); | ||
|
||
function startVerification() { | ||
/** | ||
* The following workaround is used in order to make magic links work when the | ||
* <UserProfile/> is used as a modal. In modals, the routing is virtual. For | ||
* magic links the flow needs to end by invoking the /verify path of the <UserProfile/> | ||
* that renders the <VerificationSuccessPage/>. So, we use the userProfileUrl that | ||
* defaults to Clerk Hosted Pages /user as a fallback. | ||
*/ | ||
const { routing } = profileContext; | ||
const baseUrl = routing === 'virtual' ? displayConfig.userProfileUrl : ''; | ||
const redirectUrl = buildEmailLinkRedirectUrl(profileContext, baseUrl); | ||
startEnterpriseConnectionLinkFlow({ redirectUrl }) | ||
.then(() => nextStep()) | ||
.catch(err => handleError(err, [], card.setError)); | ||
} | ||
|
||
return ( | ||
<> | ||
<VerificationLink | ||
resendButton={localizationKeys('userProfile.emailAddressPage.emailLink.resendButton')} | ||
onResendCodeClicked={startVerification} | ||
/> | ||
<FormButtonContainer> | ||
<Button | ||
variant='ghost' | ||
localizationKey={localizationKeys('userProfile.formButtonReset')} | ||
elementDescriptor={descriptors.formButtonReset} | ||
onClick={onReset} | ||
/> | ||
</FormButtonContainer> | ||
</> | ||
); | ||
}; | ||
|
||
export const VerificationSuccessPage = () => { | ||
return ( | ||
<EmailLinkStatusCard | ||
title={localizationKeys('signUp.emailLink.verifiedSwitchTab.title')} | ||
subtitle={localizationKeys('signUp.emailLink.verifiedSwitchTab.subtitle')} | ||
status='verified' | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/clerk-js/src/ui/hooks/useEnterpriseConnectionLink.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { | ||
CreateEnterpriseConnectionLinkFlowReturn, | ||
EmailAddressResource, | ||
StartEnterpriseConnectionLinkFlowParams, | ||
} from '@clerk/types'; | ||
import React from 'react'; | ||
|
||
type EnterpriseConnectionLinkable = EmailAddressResource; | ||
type EnterpriseConnectionLinkEmailAddressReturn = CreateEnterpriseConnectionLinkFlowReturn< | ||
StartEnterpriseConnectionLinkFlowParams, | ||
EmailAddressResource | ||
>; | ||
|
||
function useEnterpriseConnectionLink( | ||
resource: EnterpriseConnectionLinkable, | ||
): EnterpriseConnectionLinkEmailAddressReturn { | ||
const { startEnterpriseConnectionLinkFlow, cancelEnterpriseConnectionLinkFlow } = React.useMemo( | ||
() => resource.createEnterpriseConnectionLinkFlow(), | ||
[resource], | ||
); | ||
|
||
React.useEffect(() => { | ||
return cancelEnterpriseConnectionLinkFlow; | ||
}, []); | ||
|
||
return { | ||
startEnterpriseConnectionLinkFlow, | ||
cancelEnterpriseConnectionLinkFlow, | ||
}; | ||
} | ||
|
||
export { useEnterpriseConnectionLink }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters