// The per-account exemption from the emailed sign-in code, for an account an // outside reviewer (an App Store review, an OAuth verification) signs in with. import { useState } from "react"; import { useMutation, useQueryClient } from "@tanstack/react-query"; import { toast } from "sonner"; import { useConfirm } from "@/components/ConfirmDialog"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Switch } from "@/components/ui/switch"; import { useAdminPerm } from "@/hooks/useAdminPerm"; import { AdminPerm } from "@/lib/auth/permissions"; import { setUserLoginCodeExempt } from "@/lib/api/client/admin/users"; import type { AdminUserDetail } from "@/lib/api/models/admin"; const REASON_MAX = 500; export function UserLoginCodeCard({ user }: { user: AdminUserDetail }) { const qc = useQueryClient(); const confirm = useConfirm(); const canManage = useAdminPerm(AdminPerm.ManageTesters); const [granting, setGranting] = useState(false); const [reason, setReason] = useState(""); const exempt = !!user.login_code_exempt; function refresh() { qc.invalidateQueries({ queryKey: ["admin", "users", user.id] }); qc.invalidateQueries({ queryKey: ["admin", "users"] }); qc.invalidateQueries({ queryKey: ["admin", "testers"] }); } const grant = useMutation({ mutationFn: (why: string) => setUserLoginCodeExempt(user.id, { exempt: true, reason: why }), onSuccess: () => { refresh(); toast.success("This account will not be asked for an emailed sign-in code"); setGranting(false); setReason(""); }, onError: (e: Error) => toast.error(e.message || "Could not grant the exemption"), }); const clear = useMutation({ mutationFn: () => setUserLoginCodeExempt(user.id, { exempt: false }), onSuccess: (res) => { refresh(); toast.success( res.password_cleared ? "Exemption removed, the handed-out password cleared and every session signed out" : "Exemption removed and every session signed out", ); }, onError: (e: Error) => toast.error(e.message || "Could not remove the exemption"), }); async function onToggle(next: boolean) { if (next) { setGranting(true); return; } const ok = await confirm({ title: `Require the emailed sign-in code for ${user.email} again?`, description: user.password_expires_at ? "Every session this account holds is signed out, and the password handed out with it stops working." : "Every session this account holds is signed out. An account created under Testers also loses the password its holder chose; any other keeps its password.", confirmLabel: "Remove exemption", destructive: true, }); if (ok) await clear.mutateAsync().catch(() => undefined); } const trimmed = reason.trim(); const busy = grant.isPending || clear.isPending; return (

For an App Store or OAuth review account whose holder cannot read this instance's mail. Only the emailed code is skipped: the password, the captcha or App Attest check, the attempt limit and two-factor authentication still apply.

{exempt && (

Reason: {user.login_code_exempt_reason || "none recorded"} {user.login_code_exempt_at && ( {" "} (since {new Date(user.login_code_exempt_at).toLocaleDateString()}) )}

)} {!canManage && (

Changing this needs manage_testers.

)}
void onToggle(v)} className="mt-0.5" />
{ if (!open && !grant.isPending) { setGranting(false); setReason(""); } }} > Skip the emailed sign-in code {user.email} will sign in with its password alone, without an emailed code, on any device. Every other check still applies. The reason is kept on the account and in the admin audit log.
{ e.preventDefault(); if (trimmed !== "") grant.mutate(trimmed); }} > setReason(e.target.value)} autoFocus />

Required. Remove the exemption when the review ends.

); }