sign-out-button.tsx30 lines · main
| 1 | 'use client'; |
| 2 | |
| 3 | import { useState } from 'react'; |
| 4 | |
| 5 | export function SignOutButton() { |
| 6 | const [pending, setPending] = useState(false); |
| 7 | |
| 8 | async function onClick() { |
| 9 | setPending(true); |
| 10 | try { |
| 11 | await fetch('/api/v1/auth/sign-out', { |
| 12 | method: 'POST', |
| 13 | credentials: 'include', |
| 14 | }); |
| 15 | } finally { |
| 16 | window.location.href = '/signin'; |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | return ( |
| 21 | <button |
| 22 | type="button" |
| 23 | onClick={onClick} |
| 24 | disabled={pending} |
| 25 | className="rounded-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" |
| 26 | > |
| 27 | {pending ? 'signing out...' : 'sign out'} |
| 28 | </button> |
| 29 | ); |
| 30 | } |