Skip to content

Commit

Permalink
Merge pull request #263 from atls/feat/redirect-to-verification-after…
Browse files Browse the repository at this point in the history
…-successful-registration

Feat/redirect to verification after successful registration
  • Loading branch information
TorinAsakura authored Feb 19, 2024
2 parents a1dee29 + 5691a10 commit 1259698
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 23 deletions.
Binary file not shown.
Binary file removed .yarn/cache/fsevents-patch-6b67494872-10.zip
Binary file not shown.
67 changes: 44 additions & 23 deletions packages/identity-integration/src/flows/registration.flow.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,42 @@
import { Identity } from '@ory/kratos-client'
import { UpdateRegistrationFlowBody } from '@ory/kratos-client'
import { RegistrationFlow as KratosRegistrationFlow } from '@ory/kratos-client'
import { UiNodeInputAttributes } from '@ory/kratos-client'

import React from 'react'
import { AxiosError } from 'axios'
import { PropsWithChildren } from 'react'
import { FC } from 'react'
import { useSearchParams } from 'next/navigation'
import { useRouter } from 'next/navigation'
import { useState } from 'react'
import { useEffect } from 'react'
import { useMemo } from 'react'
import { useCallback } from 'react'

import { FlowProvider } from '../providers'
import { ValuesProvider } from '../providers'
import { ValuesStore } from '../providers'
import { SubmitProvider } from '../providers'
import { useKratosClient } from '../providers'
import { handleFlowError } from './handle-errors.util'
import { Identity } from '@ory/kratos-client'
import { UpdateRegistrationFlowBody } from '@ory/kratos-client'
import { RegistrationFlow as KratosRegistrationFlow } from '@ory/kratos-client'
import { ContinueWith as KratosContinueWith } from '@ory/kratos-client'

import { UiNodeInputAttributes } from '@ory/kratos-client'

import React from 'react'
import { AxiosError } from 'axios'
import { PropsWithChildren } from 'react'
import { FC } from 'react'
import { useSearchParams } from 'next/navigation'
import { useRouter } from 'next/navigation'
import { useState } from 'react'
import { useEffect } from 'react'
import { useMemo } from 'react'
import { useCallback } from 'react'

import { FlowProvider } from '../providers'
import { ValuesProvider } from '../providers'
import { ValuesStore } from '../providers'
import { SubmitProvider } from '../providers'
import { useKratosClient } from '../providers'
import { handleFlowError } from './handle-errors.util'

export interface RegistrationFlowProps {
onError?: (error: { id: string }) => void
returnToUrl?: string
shouldRedirect?: boolean
}

type ContinueWith = KratosContinueWith & {
flow?: {
id: string
url?: string
verifiable_address: string
}
}

export const RegistrationFlow: FC<PropsWithChildren<RegistrationFlowProps>> = ({
children,
onError,
Expand Down Expand Up @@ -121,10 +131,21 @@ export const RegistrationFlow: FC<PropsWithChildren<RegistrationFlowProps>> = ({
setIdentity(data.identity)
setIsValid(true)

const continueWithAction: ContinueWith | undefined = data.continue_with?.find(
(action) => action.action === 'show_verification_ui'
)

if (flow?.return_to) {
window.location.href = flow?.return_to
} else if (shouldRedirect) {
router.push(returnToUrl ?? '/')
if (returnToUrl) {
router.push(returnToUrl)
}
if (continueWithAction?.flow?.url) {
router.push(continueWithAction.flow.url)
} else {
router.push('/')
}
}
})
.catch(handleFlowError(router, 'registration', setFlow, returnToSettingsUrl))
Expand Down

0 comments on commit 1259698

Please sign in to comment.