admin-sign-out.tsx35 lines · main
| 1 | 'use client'; |
| 2 | |
| 3 | import { useState } from 'react'; |
| 4 | |
| 5 | /** |
| 6 | * Reuses the existing Better Auth sign-out endpoint via the same-origin |
| 7 | * /api/* rewrite (identical mechanism to the dashboard SignOutButton). |
| 8 | * Lands the operator back on the cockpit login. |
| 9 | */ |
| 10 | export function AdminSignOut() { |
| 11 | const [pending, setPending] = useState(false); |
| 12 | |
| 13 | async function onClick() { |
| 14 | setPending(true); |
| 15 | try { |
| 16 | await fetch('/api/v1/auth/sign-out', { |
| 17 | method: 'POST', |
| 18 | credentials: 'include', |
| 19 | }); |
| 20 | } finally { |
| 21 | window.location.href = '/admin/login'; |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | return ( |
| 26 | <button |
| 27 | type="button" |
| 28 | onClick={onClick} |
| 29 | disabled={pending} |
| 30 | className="rounded-[var(--radius-md)] border border-[var(--color-border)] px-3 py-1.5 font-mono text-xs text-[var(--color-text-muted)] transition hover:border-[var(--color-border-strong)] hover:text-[var(--color-text)] disabled:opacity-50" |
| 31 | > |
| 32 | {pending ? 'signing out...' : 'sign out'} |
| 33 | </button> |
| 34 | ); |
| 35 | } |