Creators grant a catalog leave to import their IMVU products (whole shop less exclusions, or listed products) from a linked IMVU account, agreeing to a versioned consent text; the catalog's team accepts or declines. Requests queue covered products (or add them to the library when imported already), suggest, or count. Importers claim jobs with the catalog's importer key, get t5de-import tokens, and the catalog registers imported revisions as published products owned by the creator. Narrowing or withdrawing a grant withdraws products; unlinking suspends grants; an hourly batch rechecks imported products with IMVU daily. Website: /imports and the console's catalog imports page. Co-Authored-By: Claude Opus 5.5 <[email protected]>
124 lines
4.2 KiB
TypeScript
124 lines
4.2 KiB
TypeScript
"use client";
|
|
import Link from "next/link";
|
|
import { useRouter } from "next/navigation";
|
|
import { useState } from "react";
|
|
import { ErrorText } from "@/components/forms";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Field, FieldDescription, FieldGroup, FieldLabel } from "@/components/ui/field";
|
|
import { Input } from "@/components/ui/input";
|
|
import { authClient } from "@/lib/auth-client";
|
|
|
|
/** Signs in with Better Auth (then a code, if two-factor sign-in is on), then goes to next (already checked to be a
|
|
* path on this site). */
|
|
export function SignInForm({ next }: { next: string }) {
|
|
const router = useRouter();
|
|
const [error, setError] = useState("");
|
|
const [pending, setPending] = useState(false);
|
|
// After the password, when two-factor sign-in is on: a code from the app, or a backup code.
|
|
const [step, setStep] = useState<"password" | "code" | "backup">("password");
|
|
|
|
const done = () => {
|
|
router.push(next);
|
|
router.refresh();
|
|
};
|
|
|
|
async function signIn(form: FormData) {
|
|
const { data, error } = await authClient.signIn.username({
|
|
username: String(form.get("username")),
|
|
password: String(form.get("password")),
|
|
});
|
|
if (error) return setError(error.message ?? "That didn't work. Try again.");
|
|
if (data && "twoFactorRedirect" in data && data.twoFactorRedirect) return setStep("code");
|
|
done();
|
|
}
|
|
|
|
async function verify(form: FormData) {
|
|
const code = String(form.get("code")).replace(/\s+/g, "");
|
|
const { error } =
|
|
step === "code"
|
|
? await authClient.twoFactor.verifyTotp({ code })
|
|
: await authClient.twoFactor.verifyBackupCode({ code });
|
|
if (error) return setError(error.message ?? "That code didn't work. Try again.");
|
|
done();
|
|
}
|
|
|
|
async function submit(form: FormData) {
|
|
setError("");
|
|
setPending(true);
|
|
await (step === "password" ? signIn(form) : verify(form));
|
|
setPending(false);
|
|
}
|
|
|
|
return (
|
|
<form
|
|
onSubmit={(e) => {
|
|
e.preventDefault();
|
|
void submit(new FormData(e.currentTarget));
|
|
}}
|
|
>
|
|
{step === "password" ? (
|
|
<FieldGroup>
|
|
<Field>
|
|
<FieldLabel htmlFor="username">Username</FieldLabel>
|
|
<Input id="username" name="username" autoComplete="username" required autoFocus />
|
|
</Field>
|
|
<Field>
|
|
<FieldLabel htmlFor="password">Password</FieldLabel>
|
|
<Input id="password" name="password" type="password" autoComplete="current-password" required />
|
|
</Field>
|
|
{error && <ErrorText>{error}</ErrorText>}
|
|
<Field>
|
|
<Button type="submit" disabled={pending}>
|
|
{pending ? "Signing in…" : "Sign in"}
|
|
</Button>
|
|
<FieldDescription className="text-center">
|
|
No account? <Link href="/signup">Create one</Link>
|
|
</FieldDescription>
|
|
</Field>
|
|
</FieldGroup>
|
|
) : (
|
|
<FieldGroup key={step}>
|
|
<Field>
|
|
<FieldLabel htmlFor="code">
|
|
{step === "code" ? "Code from your authenticator app" : "Backup code"}
|
|
</FieldLabel>
|
|
<Input
|
|
id="code"
|
|
name="code"
|
|
required
|
|
autoFocus
|
|
autoComplete="one-time-code"
|
|
{...(step === "code"
|
|
? {
|
|
inputMode: "numeric",
|
|
pattern: "\\s*[0-9]{6}\\s*",
|
|
maxLength: 8,
|
|
}
|
|
: { maxLength: 32 })}
|
|
className="font-mono"
|
|
/>
|
|
</Field>
|
|
{error && <ErrorText>{error}</ErrorText>}
|
|
<Field>
|
|
<Button type="submit" disabled={pending}>
|
|
{pending ? "Checking…" : "Sign in"}
|
|
</Button>
|
|
<FieldDescription className="text-center">
|
|
<button
|
|
type="button"
|
|
className="underline underline-offset-4"
|
|
onClick={() => {
|
|
setError("");
|
|
setStep(step === "code" ? "backup" : "code");
|
|
}}
|
|
>
|
|
{step === "code" ? "Use a backup code instead" : "Use your authenticator app instead"}
|
|
</button>
|
|
</FieldDescription>
|
|
</Field>
|
|
</FieldGroup>
|
|
)}
|
|
</form>
|
|
);
|
|
}
|