Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add email to query params #265

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 35 additions & 25 deletions packages/identity-integration/src/flows/registration.flow.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
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'
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
passEmail: boolean
}

type ContinueWith = KratosContinueWith & {
Expand All @@ -42,6 +42,7 @@ export const RegistrationFlow: FC<PropsWithChildren<RegistrationFlowProps>> = ({
onError,
returnToUrl,
shouldRedirect = true,
passEmail = false,
}) => {
const [flow, setFlow] = useState<KratosRegistrationFlow>()
const [identity, setIdentity] = useState<Identity>()
Expand Down Expand Up @@ -142,7 +143,16 @@ export const RegistrationFlow: FC<PropsWithChildren<RegistrationFlowProps>> = ({
router.push(returnToUrl)
}
if (continueWithAction?.flow?.url) {
router.push(continueWithAction.flow.url)
if (passEmail) {
const url = new URL(continueWithAction.flow.url)
const params = url.searchParams
const email = continueWithAction.flow.verifiable_address
params.set('email', email)
const newUrlString = `${url.origin}${url.pathname}?${params.toString()}`
router.push(newUrlString)
} else {
router.push(continueWithAction.flow.url)
}
} else {
router.push('/')
}
Expand Down