directus permissions fixes and rig_type addition

This commit is contained in:
makearmy 2025-09-26 17:29:47 -04:00
parent 4deeac8e43
commit 226fcc8013
3 changed files with 355 additions and 289 deletions

View file

@ -1,43 +1,49 @@
// components/SignOutButton.tsx
"use client";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { useRouter, usePathname } from "next/navigation";
import { Button } from "@/components/ui/button";
type Props = {
className?: string;
/** Where to send users after logout */
redirectTo?: string; // default /auth/sign-in
};
export default function SignOutButton({
className,
redirectTo = "/sign-in",
children = "Sign out",
}: {
className?: string;
redirectTo?: string;
children?: React.ReactNode;
}) {
const r = useRouter();
const [busy, setBusy] = useState(false);
redirectTo = "/auth/sign-in",
}: Props) {
const [pending, setPending] = useState(false);
const router = useRouter();
const pathname = usePathname();
async function onClick() {
if (busy) return;
setBusy(true);
if (pending) return;
setPending(true);
try {
await fetch("/api/auth/logout", { method: "POST" });
r.push(redirectTo);
r.refresh();
// include ?next= so they can land back here after re-auth if desired
const next = pathname ? `?next=${encodeURIComponent(pathname)}` : "";
router.push(redirectTo + next);
router.refresh(); // ensure cookies are revalidated client-side
} catch {
// ignore; worst case user can hard-refresh
router.push(redirectTo);
} finally {
setBusy(false);
setPending(false);
}
}
return (
<button
<Button
type="button"
onClick={onClick}
className={className ?? "text-sm underline hover:opacity-80"}
disabled={busy}
className={className}
variant="ghost"
size="sm"
disabled={pending}
>
{busy ? "Signing out…" : children}
</button>
{pending ? "Signing out…" : "Sign out"}
</Button>
);
}