Skip to content

Commit

Permalink
feat: add new optional prop shouldRedirect to registration flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelfimov committed Dec 4, 2023
1 parent ced33a1 commit e4f6d29
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/identity-integration/src/flows/registration.flow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ import { handleFlowError } from './handle-errors.util
export interface RegistrationFlowProps {
onError?: (error: { id: string }) => void
returnToUrl?: string
shouldRedirect?: boolean
}

export const RegistrationFlow: FC<PropsWithChildren<RegistrationFlowProps>> = ({
children,
onError,
returnToUrl,
shouldRedirect = true,
}) => {
const [flow, setFlow] = useState<KratosRegistrationFlow>()
const [identity, setIdentity] = useState<Identity>()
Expand Down Expand Up @@ -60,7 +62,7 @@ export const RegistrationFlow: FC<PropsWithChildren<RegistrationFlowProps>> = ({

kratosClient
.createBrowserRegistrationFlow(
{ returnTo: returnTo?.toString() ?? returnToUrl },
{ returnTo: shouldRedirect ? returnTo?.toString() ?? returnToUrl : undefined },
{
withCredentials: true,
}
Expand Down Expand Up @@ -116,7 +118,7 @@ export const RegistrationFlow: FC<PropsWithChildren<RegistrationFlowProps>> = ({

if (flow?.return_to) {
window.location.href = flow?.return_to
} else {
} else if (shouldRedirect) {
router.push(returnToUrl ?? '/')
}
})
Expand Down

0 comments on commit e4f6d29

Please sign in to comment.