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]>
97 lines
4.0 KiB
TypeScript
97 lines
4.0 KiB
TypeScript
import type { Metadata } from "next";
|
|
import Link from "next/link";
|
|
import { PageHeader, Tag } from "@/components/status";
|
|
import { DateTime } from "@/components/time";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Card, CardContent } from "@/components/ui/card";
|
|
import { Input } from "@/components/ui/input";
|
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
|
import { api, unwrap } from "@/lib/api";
|
|
import { ConsoleNav, requireModerator } from "../console-nav";
|
|
|
|
export const metadata: Metadata = { title: "People" };
|
|
|
|
export default async function People({
|
|
searchParams,
|
|
}: {
|
|
searchParams: Promise<{ q?: string | string[]; waiting?: string | string[] }>;
|
|
}) {
|
|
const params = await searchParams;
|
|
const q = typeof params.q === "string" ? params.q.slice(0, 64) : "";
|
|
const waiting = params.waiting === "true";
|
|
const query = new URLSearchParams({ ...(q ? { q } : {}), ...(waiting ? { waiting: "true" } : {}) }).toString();
|
|
await requireModerator(`/console/people${query ? `?${query}` : ""}`);
|
|
const { people } = unwrap(await api.console.people.get({ query: { ...(q ? { q } : {}), ...(waiting ? { waiting: true } : {}) } }));
|
|
|
|
return (
|
|
<>
|
|
<PageHeader title="People" />
|
|
<ConsoleNav />
|
|
<Card>
|
|
<CardContent className="space-y-6">
|
|
<div className="flex flex-wrap items-center gap-4">
|
|
<form action="/console/people" className="flex max-w-md flex-1 gap-2">
|
|
<Input type="search" name="q" defaultValue={q} placeholder="T5DE or IMVU username" aria-label="Search" />
|
|
{waiting && <input type="hidden" name="waiting" value="true" />}
|
|
<Button type="submit" variant="outline">
|
|
Search
|
|
</Button>
|
|
</form>
|
|
<Link
|
|
href={waiting ? "/console/people" : "/console/people?waiting=true"}
|
|
className="text-sm text-muted-foreground underline-offset-4 hover:underline"
|
|
>
|
|
{waiting ? "Show everyone" : "Waiting for approval"}
|
|
</Link>
|
|
</div>
|
|
{people.length === 0 ? (
|
|
<p className="text-sm text-muted-foreground">{waiting ? "Nobody is waiting." : "Nobody found."}</p>
|
|
) : (
|
|
<Table>
|
|
<TableHeader>
|
|
<TableRow>
|
|
<TableHead>Username</TableHead>
|
|
<TableHead>Role</TableHead>
|
|
<TableHead>Link cap</TableHead>
|
|
<TableHead>Joined</TableHead>
|
|
<TableHead />
|
|
</TableRow>
|
|
</TableHeader>
|
|
<TableBody>
|
|
{people.map((p) => (
|
|
<TableRow key={p.id}>
|
|
<TableCell>
|
|
<Link href={`/console/people/${p.id}`} className="font-medium underline-offset-4 hover:underline">
|
|
{p.username}
|
|
</Link>
|
|
</TableCell>
|
|
<TableCell>
|
|
<span className="capitalize">{p.role}</span>
|
|
{p.role !== "user" && !p.twoFactor && (
|
|
<span className="ml-2 text-xs text-muted-foreground">no two-factor</span>
|
|
)}
|
|
</TableCell>
|
|
<TableCell className="tabular-nums">{p.linkCap}</TableCell>
|
|
<TableCell className="text-muted-foreground">
|
|
<DateTime iso={p.createdAt} dateOnly />
|
|
</TableCell>
|
|
<TableCell className="text-right">
|
|
{p.banned ? (
|
|
<Tag tone="danger">banned</Tag>
|
|
) : p.kind === "basic" ? (
|
|
<Tag>Discord only</Tag>
|
|
) : (
|
|
!p.approved && <Tag tone="strong">waiting</Tag>
|
|
)}
|
|
</TableCell>
|
|
</TableRow>
|
|
))}
|
|
</TableBody>
|
|
</Table>
|
|
)}
|
|
</CardContent>
|
|
</Card>
|
|
</>
|
|
);
|
|
}
|