added user rig submission, logout | initial
This commit is contained in:
parent
9261fbc165
commit
b341a3675e
8 changed files with 635 additions and 420 deletions
43
app/components/SignOutButton.tsx
Normal file
43
app/components/SignOutButton.tsx
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
// components/SignOutButton.tsx
|
||||
"use client";
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
|
||||
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);
|
||||
|
||||
async function onClick() {
|
||||
if (busy) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
await fetch("/api/auth/logout", { method: "POST" });
|
||||
r.push(redirectTo);
|
||||
r.refresh();
|
||||
} catch {
|
||||
// ignore; worst case user can hard-refresh
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClick}
|
||||
className={className ?? "text-sm underline hover:opacity-80"}
|
||||
disabled={busy}
|
||||
>
|
||||
{busy ? "Signing out…" : children}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue