import type { Metadata } from "next"; import { redirect } from "next/navigation"; import { DiscordButton } from "@/components/discord-button"; import { ErrorText } from "@/components/forms"; import { NarrowCard } from "@/components/narrow-card"; import { Separator } from "@/components/ui/separator"; import { api, getMe, unwrap } from "@/lib/api"; import { discordError } from "@/lib/discord"; import { continueURL, requestedProvider, requestingClient } from "@/lib/oauth"; import { safeNext } from "@/lib/paths"; import { SignInForm } from "./signin-form"; export const metadata: Metadata = { title: "Sign in" }; export default async function SignIn({ searchParams }: { searchParams: Promise> }) { const params = await searchParams; // Opened for another T5DE site (Music): back to it once signed in. const forSite = continueURL(params); const next = forSite ?? safeNext(params.next); if (await getMe()) redirect(next); const { discord } = unwrap(await api.hub.get()); const clientId = requestingClient(params); const site = forSite && clientId ? (await api.oauth.clients({ clientId }).get()).data : undefined; const siteName = site && "client" in site ? site.client.name : undefined; const error = discordError(params.error); // The site asked for Discord (its "Sign in with Discord" button): go straight there, unless that just failed. const autoDiscord = discord && forSite !== undefined && requestedProvider(params) === "discord" && !error; return (
{error && {error}} {discord && ( <>
or with your username
)}
); }