import { redirect } from "next/navigation" import React from "react" import { z } from "zod" import { env } from "@/env/server" import Image from "@/components/Image" import { Redirect } from "@/components/Redirect" import Link from "@/components/TempDesignSystem/Link" import Body from "@/components/TempDesignSystem/Text/Body" import Footnote from "@/components/TempDesignSystem/Text/Footnote" import Title from "@/components/TempDesignSystem/Text/Title" import { getIntl } from "@/i18n" import { SASModal } from "../components/SASModal" import type { LangParams, PageArgs, SearchParams } from "@/types/params" import type { State } from "../sasUtils" const searchParamsSchema = z.object({ intent: z.enum(["link"]), }) export default async function SASxScandicLoginPage({ searchParams, params, }: PageArgs & SearchParams) { const result = searchParamsSchema.safeParse(searchParams) if (!result.success) { // TOOD where to redirect? redirect(`/${params.lang}/sas-x-scandic/link`) } const parsedParams = result.data const intl = await getIntl() const redirectUri = new URL( "/en/sas-x-scandic/callback", env.PUBLIC_URL ).toString() const state: State = { intent: parsedParams.intent } const urlState = encodeURIComponent(JSON.stringify(state)) const clientId = env.SAS_AUTH_CLIENTID const sasLoginHostname = env.SAS_AUTH_ENDPOINT const audience = "eb-partner-api" // TODO check if this is correct scopes const scope = encodeURIComponent("openid profile email") const loginLink = `${sasLoginHostname}/oauth/authorize?response_type=code&client_id=${clientId}&redirect_uri=${redirectUri}&scope=${scope}&state=${urlState}&audience=${audience}` return ( {intl.formatMessage({ id: "Redirecting you to SAS" })} {intl.formatMessage({ id: "In order to verify your account linking we will ask you to sign in to your SAS EuroBonus account.", })} {intl.formatMessage( { id: "If you are not redirected automatically, please click here.", }, { loginLink: (str) => ( {str} ), } )} ) }