First half of docs/music.md's phase 1 (Accounts): Discord sign-in and basic accounts. The OIDC provider (Music as a trusted client, the `imvu` scope) is the next PR.
**Discord sign-in** (on when `DISCORD_CLIENT_ID` and `DISCORD_CLIENT_SECRET` are set; Discord redirects to `<API_URL>/api/auth/callback/discord`):
- The first time, it makes a **basic account** (`user.kind = "basic"`): Discord's name and email, no username or password. Basic accounts are for T5DE's other sites (Music); on the hub, every route but `/me` and `/account/finish` answers 403 `finish_setup`, and the website shows "Finish Setting Up Your Account" in place of every page.
- Only a **verified** Discord email (`user.validateUserInfo`): `email_not_verified`, or `email_not_found` for Discord accounts without one.
- **Never linked by matching email** (`accountLinking.disableImplicitLinking`): a Discord account whose email belongs to another T5DE account ends with `account_not_linked`, and the sign-in page says to sign in and link Discord from Account.
- Basic accounts don't count toward "the first account is an admin".
**Finishing setup**: `POST /api/v1/account/finish {username, password}` adds a password sign-in and a username in one transaction and makes the account a member (waiting for approval if registration is closed). Discord stays linked.
**Members** link Discord from the Account page (`/api/auth/link-social`; `account_already_linked_to_different_user` if it belongs to another account; merging basic accounts into members is phase 5) and unlink it (`DELETE /api/v1/account/discord`, audited). The console tags basic accounts "Discord only".
First half of docs/music.md's phase 1 (Accounts): Discord sign-in and basic accounts. The OIDC provider (Music as a trusted client, the `imvu` scope) is the next PR.
**Discord sign-in** (on when `DISCORD_CLIENT_ID` and `DISCORD_CLIENT_SECRET` are set; Discord redirects to `<API_URL>/api/auth/callback/discord`):
- The first time, it makes a **basic account** (`user.kind = "basic"`): Discord's name and email, no username or password. Basic accounts are for T5DE's other sites (Music); on the hub, every route but `/me` and `/account/finish` answers 403 `finish_setup`, and the website shows "Finish Setting Up Your Account" in place of every page.
- Only a **verified** Discord email (`user.validateUserInfo`): `email_not_verified`, or `email_not_found` for Discord accounts without one.
- **Never linked by matching email** (`accountLinking.disableImplicitLinking`): a Discord account whose email belongs to another T5DE account ends with `account_not_linked`, and the sign-in page says to sign in and link Discord from Account.
- Basic accounts don't count toward "the first account is an admin".
**Finishing setup**: `POST /api/v1/account/finish {username, password}` adds a password sign-in and a username in one transaction and makes the account a member (waiting for approval if registration is closed). Discord stays linked.
**Members** link Discord from the Account page (`/api/auth/link-social`; `account_already_linked_to_different_user` if it belongs to another account; merging basic accounts into members is phase 5) and unlink it (`DELETE /api/v1/account/discord`, audited). The console tags basic accounts "Discord only".
Also: Better Auth 1.7.14 → 1.7.26 (the OAuth provider package in the next PR needs it); migration `0021_account_kind` (one column, default `member`).
Tests: `apps/api/test/discord.test.ts` runs Better Auth's real social sign-in and callback against a stand-in for Discord's token and profile endpoints (basic account, verified email only, no linking by email, finishing setup, closed registration, linking and unlinking). Full suite 68/68, `check-types` and `build` pass locally. The new pages (sign-in's Discord button, Finish Setting Up, the Discord card) aren't checked in a browser yet: that needs the Discord application, then staging.
Before deploying: a Discord application with both redirect URLs (prod and staging), and its ID and secret in the hub stacks' secrets (dhkatz/infra).
Also: Better Auth 1.7.14 → 1.7.26 (the OAuth provider package in the next PR needs it); migration `0021_account_kind` (one column, default `member`).
Tests: `apps/api/test/discord.test.ts` runs Better Auth's real social sign-in and callback against a stand-in for Discord's token and profile endpoints (basic account, verified email only, no linking by email, finishing setup, closed registration, linking and unlinking). Full suite 68/68, `check-types` and `build` pass locally. The new pages (sign-in's Discord button, Finish Setting Up, the Discord card) aren't checked in a browser yet: that needs the Discord application, then staging.
Before deploying: a Discord application with both redirect URLs (prod and staging), and its ID and secret in the hub stacks' secrets (dhkatz/infra).
Co-authored-by: dhkatz <[email protected]>
162 lines
6.1 KiB
TypeScript
162 lines
6.1 KiB
TypeScript
import type { Metadata } from "next";
|
|
import Link from "next/link";
|
|
import { redirect } from "next/navigation";
|
|
import { ActionForm, SubmitButton } from "@/components/forms";
|
|
import { PageHeader, Tag } from "@/components/status";
|
|
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
|
import { Input } from "@/components/ui/input";
|
|
import { api, getMe, isModerator, unwrap } from "@/lib/api";
|
|
import { discordError } from "@/lib/discord";
|
|
import { claimCreator, linkAccount, signOutComputers } from "./actions";
|
|
import { AgeCard } from "./age-card";
|
|
import { ChallengeCard } from "./challenge-card";
|
|
import { DiscordCard } from "./discord-card";
|
|
import { LinkCard } from "./link-card";
|
|
import { TokensCard } from "./tokens-card";
|
|
import { TwoFactorCard } from "./two-factor-card";
|
|
|
|
export const metadata: Metadata = { title: "Account" };
|
|
|
|
export default async function Account({ searchParams }: { searchParams: Promise<{ welcome?: string; age?: string; error?: string }> }) {
|
|
const me = await getMe();
|
|
if (!me) redirect("/signin?next=/account");
|
|
const [account, age, tokens] = await Promise.all([
|
|
api.account.get().then(unwrap),
|
|
api.age.get().then(unwrap),
|
|
api.account.tokens.get().then(unwrap),
|
|
]);
|
|
const { person, links, challenges, computers } = account;
|
|
const params = await searchParams;
|
|
const welcome = params.welcome !== undefined;
|
|
|
|
return (
|
|
<div className="space-y-6">
|
|
<PageHeader title="Your account">
|
|
<span className="flex flex-wrap items-center gap-2">
|
|
Signed in as {person.username}
|
|
{isModerator(person) && <Tag tone="strong">{person.role}</Tag>}
|
|
</span>
|
|
</PageHeader>
|
|
|
|
{welcome && (
|
|
<Alert>
|
|
<AlertTitle>Welcome to T5DE, {person.username}.</AlertTitle>
|
|
<AlertDescription>Link an IMVU account below to get started.</AlertDescription>
|
|
</Alert>
|
|
)}
|
|
|
|
<Card>
|
|
<CardHeader>
|
|
<CardTitle>IMVU accounts</CardTitle>
|
|
<CardDescription>
|
|
{links.length} of {person.linkCap}
|
|
</CardDescription>
|
|
</CardHeader>
|
|
<CardContent>
|
|
{links.length > 0 ? (
|
|
<ul className="divide-y">
|
|
{links.map((link) => (
|
|
<LinkCard key={link.imvuId} link={link} />
|
|
))}
|
|
</ul>
|
|
) : (
|
|
<p className="text-sm text-muted-foreground">No IMVU accounts linked yet.</p>
|
|
)}
|
|
</CardContent>
|
|
</Card>
|
|
|
|
{account.claims.map((c) => (
|
|
<Card key={c.imvuId}>
|
|
<CardHeader>
|
|
<CardTitle>Your IMVU Products on T5DE</CardTitle>
|
|
<CardDescription>
|
|
Before you joined, you agreed with T5DE to bring {c.username}'s products here, and an admin recorded
|
|
it. They're waiting for you: {c.products} imported product{c.products === 1 ? "" : "s"} and{" "}
|
|
{c.grants} catalog{c.grants === 1 ? "" : "s"} hosting them. Claim them to manage them yourself, or to
|
|
withdraw them.
|
|
</CardDescription>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<ActionForm action={claimCreator} fields={{ imvuId: c.imvuId }}>
|
|
<SubmitButton pendingLabel="Claiming…">Claim them</SubmitButton>
|
|
</ActionForm>
|
|
</CardContent>
|
|
</Card>
|
|
))}
|
|
|
|
{challenges.map((c) => (
|
|
<ChallengeCard key={c.imvuId} challenge={c} />
|
|
))}
|
|
|
|
<Card>
|
|
<CardHeader>
|
|
<CardTitle>Link an IMVU account</CardTitle>
|
|
</CardHeader>
|
|
<CardContent className="space-y-4">
|
|
{account.canLink ? (
|
|
<ActionForm action={linkAccount}>
|
|
<div className="flex max-w-md gap-2">
|
|
<Input name="username" placeholder="IMVU username" required maxLength={64} aria-label="IMVU username" />
|
|
<SubmitButton pendingLabel="Looking…">Next</SubmitButton>
|
|
</div>
|
|
</ActionForm>
|
|
) : (
|
|
<p className="text-sm">
|
|
You've linked as many IMVU accounts as you can ({person.linkCap}). Ask a moderator if you need more.
|
|
</p>
|
|
)}
|
|
<p className="text-sm text-muted-foreground">
|
|
Other people can't see which IMVU accounts are yours. Adult IMVU accounts can see adult community
|
|
products: those IMVU has age verified (or with Access Pass), or all of them once you verify your age below.
|
|
</p>
|
|
<p className="text-sm text-muted-foreground">
|
|
Made products on IMVU?{" "}
|
|
<Link href="/imports" className="text-foreground underline underline-offset-4">
|
|
Bring them to T5DE
|
|
</Link>
|
|
.
|
|
</p>
|
|
</CardContent>
|
|
</Card>
|
|
|
|
<AgeCard age={age} back={params.age === "back"} />
|
|
|
|
{account.discord.available && <DiscordCard linked={account.discord.linked} error={discordError(params.error)} />}
|
|
|
|
<Card>
|
|
<CardHeader>
|
|
<CardTitle>T5DE on your computers</CardTitle>
|
|
</CardHeader>
|
|
<CardContent className="space-y-4">
|
|
<p className="text-sm text-muted-foreground">
|
|
{computers > 0
|
|
? `Signed in on ${computers} computer${computers === 1 ? "" : "s"}.`
|
|
: "Not signed in on any computer yet."}{" "}
|
|
To sign T5DE in, it shows a code to enter at{" "}
|
|
<Link href="/device" className="text-foreground underline underline-offset-4">
|
|
/device
|
|
</Link>
|
|
.
|
|
</p>
|
|
{computers > 0 && (
|
|
<ActionForm action={signOutComputers}>
|
|
<SubmitButton
|
|
variant="outline"
|
|
pendingLabel="Signing out…"
|
|
confirm="Sign T5DE out on all your computers?"
|
|
>
|
|
Sign out everywhere
|
|
</SubmitButton>
|
|
</ActionForm>
|
|
)}
|
|
</CardContent>
|
|
</Card>
|
|
|
|
<TwoFactorCard enabled={account.twoFactor.enabled} neededFor={account.twoFactor.neededFor} />
|
|
|
|
<TokensCard data={tokens} />
|
|
</div>
|
|
);
|
|
}
|