The hub as an OpenID Connect provider for T5DE Music
This commit is contained in:
1 parent
f05874f800
commit
9112e3cc30
20 files changed
+6531
-29
No files matched your search
@@ -6,28 +6,35 @@ 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<{ next?: string | string[]; error?: string | string[] }>;
|
||||
}) {
|
||||
export default async function SignIn({ searchParams }: { searchParams: Promise<Record<string, string | string[] | undefined>> }) {
|
||||
const params = await searchParams;
|
||||
const next = safeNext(params.next);
|
||||
// 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 (
|
||||
<NarrowCard title="Sign in" description="to your T5DE account.">
|
||||
<NarrowCard
|
||||
title="Sign in"
|
||||
description={siteName ? `with your T5DE account to continue to ${siteName}.` : "to your T5DE account."}
|
||||
>
|
||||
<div className="space-y-6">
|
||||
{error && <ErrorText>{error}</ErrorText>}
|
||||
{discord && (
|
||||
<>
|
||||
<DiscordButton mode="sign-in" next={next} />
|
||||
<DiscordButton mode="sign-in" next={next} auto={autoDiscord} />
|
||||
<div className="flex items-center gap-3 text-xs text-muted-foreground">
|
||||
<Separator className="flex-1" />
|
||||
or with your username
|
||||
|
||||
Reference in new issue
Block a user