Files
web/app/[lang]/(partner)/(sas)/(protected)/sas-x-scandic/link/page.tsx
Anton Gunnarsson 18288cb849 Merged in feat/sas-otp-error-handling (pull request #1272)
Feat/sas otp error handling

* Improve error handling for SAS OTP
* Remove failing and deprecated test

Approved-by: Joakim Jäderberg
2025-02-07 14:18:00 +00:00

47 lines
1.2 KiB
TypeScript

import { redirect } from "next/navigation"
import React from "react"
import { getProfileSafely } from "@/lib/trpc/memoizedRequests"
import { AlreadyLinkedError } from "../components/AlreadyLinkedError"
import { SASModal } from "../components/SASModal"
import { LinkAccountForm } from "./LinkAccountForm"
import type { LangParams, PageArgs } from "@/types/params"
export default async function SASxScandicLinkPage({
params,
}: PageArgs<LangParams>) {
const profile = await getProfileSafely()
// TODO actually check if profile is already linked
const alreadyLinked = false
async function handleLinkAccount(dateOfBirth: string) {
"use server"
if (dateOfBirth !== profile?.dateOfBirth) {
// TODO update users date of birth here
console.log("updating date of birth")
}
return {
redirectUrl: `/${params.lang}/sas-x-scandic/login?intent=link`,
success: true,
}
}
if (alreadyLinked) {
redirect(`/${params.lang}/sas-x-scandic/error?errorCode=alreadyLinked`)
}
return (
<SASModal>
<LinkAccountForm
initialDateOfBirth={profile?.dateOfBirth ?? null}
onSubmit={handleLinkAccount}
/>
</SASModal>
)
}