fix: netlify doesn't seem to handle redirects in a server action therefor we do the redirect on the client instead

This commit is contained in:
Joakim Jäderberg
2025-02-06 09:54:52 +00:00
parent 8ecaac4b52
commit c21d7bec62
4 changed files with 21 additions and 6 deletions

View File

@@ -1,6 +1,7 @@
"use client"
import Image from "next/image"
import { useRouter } from "next/navigation"
import { type ReactNode, useTransition } from "react"
import { FormProvider, useForm } from "react-hook-form"
import { useIntl } from "react-intl"
@@ -24,8 +25,11 @@ export function LinkAccountForm({
onSubmit,
}: {
initialDateOfBirth: string | null
onSubmit: (dateOfBirth: string) => Promise<void>
onSubmit: (
dateOfBirth: string
) => Promise<{ success: boolean; redirectUrl?: string }>
}) {
const router = useRouter()
let [isPending, startTransition] = useTransition()
const intl = useIntl()
const form = useForm<LinkAccountForm>({
@@ -39,7 +43,12 @@ export function LinkAccountForm({
startTransition(async () => {
if (!data.dateOfBirth || !data.termsAndConditions) return
await onSubmit(data.dateOfBirth)
const result = await onSubmit(data.dateOfBirth)
if (!result.success || !result.redirectUrl) {
throw new Error("Unable to redirect")
}
router.push(result.redirectUrl)
})
})