feat: quiz
This commit is contained in:
+15
-9
@@ -4,7 +4,7 @@ import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import Link from "next/link";
|
||||
import { toast } from "sonner";
|
||||
import { api, AdminError, type Me } from "@/lib/api";
|
||||
import { api, staff, AdminError, type Me } from "@/lib/api";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
|
||||
@@ -17,17 +17,23 @@ export default function LoginPage() {
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
// Once authenticated, only admins may proceed. Non-admins are signed back
|
||||
// out so an ordinary account can't sit in an authenticated-but-forbidden
|
||||
// state against the admin origin.
|
||||
async function gateAdmin(user: Me) {
|
||||
if (user.role === "admin") {
|
||||
// Once authenticated, only staff may proceed. Non-staff — and staff a
|
||||
// superadmin has blocked — are signed back out, so an ordinary account
|
||||
// can't sit in an authenticated-but-forbidden state against this origin.
|
||||
async function gateAdmin(_user: Me) {
|
||||
try {
|
||||
await staff.me();
|
||||
router.replace("/");
|
||||
return;
|
||||
} catch (err) {
|
||||
await api.logout().catch(() => {});
|
||||
setError(
|
||||
err instanceof AdminError && /suspended/i.test(err.message)
|
||||
? "Your admin access has been suspended."
|
||||
: "This account doesn't have admin access.",
|
||||
);
|
||||
setStage("credentials");
|
||||
}
|
||||
await api.logout().catch(() => {});
|
||||
setError("This account doesn't have admin access.");
|
||||
setStage("credentials");
|
||||
}
|
||||
|
||||
async function onCredentials(e: React.FormEvent) {
|
||||
|
||||
Reference in New Issue
Block a user