import i18n from "~/i18next.server"; import { LoaderFunctionArgs, MetaFunction } from "@remix-run/node"; import { Link, useLoaderData, useRouteLoaderData } from "@remix-run/react"; import { Button, ListGroup } from "react-bootstrap"; import { loader as settingsLoader } from "~/routes/settings/route"; import { useTranslation } from "react-i18next"; import { AuthMethod, MeUser } from "~/lib/api/user"; import serverRequest from "~/lib/request.server"; import { AuthUrls } from "~/lib/api/auth"; export const meta: MetaFunction = ({ data }) => { return [{ title: `${data?.meta.title || "Authentication"} • pronouns.cc` }]; }; export const loader = async ({ request }: LoaderFunctionArgs) => { const t = await i18n.getFixedT(request); const urls = await serverRequest("POST", "/auth/urls", { isInternal: true }); return { urls, meta: { title: t("settings.auth.title") } }; }; export default function AuthSettings() { const { urls } = useLoaderData(); const { user } = useRouteLoaderData("routes/settings")!; return (
{urls.email_enabled && } {urls.discord && }
); } function EmailSettings({ user }: { user: MeUser }) { const { t } = useTranslation(); const oneAuthMethod = user.auth_methods.length === 1; const emails = user.auth_methods.filter((m) => m.type === "EMAIL"); return ( <>

{t("settings.auth.email-addresses")}

{emails.length > 0 && ( <> {emails.map((e) => ( ))} )} {emails.length < 3 && (

{/* @ts-expect-error as=Link */}

)} ); } function EmailRow({ email, disabled }: { email: AuthMethod; disabled: boolean }) { const { t } = useTranslation(); return (
{email.remote_id}
{!disabled && (
{t("settings.auth.remove-auth-method")}
)}
); } function DiscordSettings({ user }: { user: MeUser }) { const { t } = useTranslation(); const oneAuthMethod = user.auth_methods.length === 1; const discordAccounts = user.auth_methods.filter((m) => m.type === "DISCORD"); return ( <>

{t("settings.auth.discord-accounts")}

{discordAccounts.length > 0 && ( <> {discordAccounts.map((a) => ( ))} )} {discordAccounts.length < 3 && (

{/* @ts-expect-error as=Link */}

)} ); } function FediverseSettings({ user }: { user: MeUser }) { const { t } = useTranslation(); const oneAuthMethod = user.auth_methods.length === 1; const fediAccounts = user.auth_methods.filter((m) => m.type === "FEDIVERSE"); return ( <>

{t("settings.auth.fediverse-accounts")}

{fediAccounts.length > 0 && ( <> {fediAccounts.map((a) => ( ))} )} {fediAccounts.length < 3 && (

{/* @ts-expect-error as=Link */}

)} ); } function NonEmailRow({ account, disabled }: { account: AuthMethod; disabled: boolean }) { const { t } = useTranslation(); return (
{account.remote_username} {account.type !== "FEDIVERSE" && <>({account.remote_id})}
{!disabled && (
{t("settings.auth.remove-auth-method")}
)}
); }