44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
import { redirect } from "next/navigation";
|
|
import { auth } from "@/src/lib/auth";
|
|
import { verifyLinkingToken } from "@/src/lib/services/account-linking";
|
|
import LinkAccountClient from "./LinkAccountClient";
|
|
|
|
interface LinkAccountPageProps {
|
|
searchParams: {
|
|
error?: string;
|
|
};
|
|
}
|
|
|
|
export default async function LinkAccountPage({ searchParams }: LinkAccountPageProps) {
|
|
const session = await auth();
|
|
|
|
// Already authenticated - redirect
|
|
if (session) {
|
|
redirect("/");
|
|
}
|
|
|
|
// Get linking token from error parameter (NextAuth redirects with error param)
|
|
const errorParam = searchParams.error || "";
|
|
|
|
if (!errorParam.startsWith("LINKING_REQUIRED:")) {
|
|
redirect("/login?error=Invalid linking request");
|
|
}
|
|
|
|
const linkingToken = errorParam.replace("LINKING_REQUIRED:", "");
|
|
|
|
// Verify token and decode
|
|
const tokenPayload = await verifyLinkingToken(linkingToken);
|
|
|
|
if (!tokenPayload) {
|
|
redirect("/login?error=Linking token expired or invalid");
|
|
}
|
|
|
|
return (
|
|
<LinkAccountClient
|
|
provider={tokenPayload.provider}
|
|
email={tokenPayload.email}
|
|
linkingToken={linkingToken}
|
|
/>
|
|
);
|
|
}
|