sign-out-button.tsx37 lines · main
| 1 | 'use client'; |
| 2 | |
| 3 | import { useRouter } from 'next/navigation'; |
| 4 | import { useState } from 'react'; |
| 5 | |
| 6 | interface Props { |
| 7 | projectId: string; |
| 8 | } |
| 9 | |
| 10 | export function SignOutButton({ projectId }: Props) { |
| 11 | const router = useRouter(); |
| 12 | const [pending, setPending] = useState(false); |
| 13 | |
| 14 | async function signOut(): Promise<void> { |
| 15 | setPending(true); |
| 16 | try { |
| 17 | await fetch(`/api/v1/auth-tenant/sign-out`, { |
| 18 | method: 'POST', |
| 19 | credentials: 'include', |
| 20 | headers: { 'x-briven-project-id': projectId }, |
| 21 | }); |
| 22 | } finally { |
| 23 | router.replace(`/auth/${projectId}/sign-in`); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | return ( |
| 28 | <button |
| 29 | type="button" |
| 30 | onClick={() => void signOut()} |
| 31 | disabled={pending} |
| 32 | className="self-start rounded-md border border-[var(--color-border)] px-3 py-1.5 font-mono text-xs text-[var(--color-text-muted)] hover:border-[var(--color-error)] hover:text-[var(--color-error)] disabled:opacity-50" |
| 33 | > |
| 34 | {pending ? 'signing out…' : 'sign out'} |
| 35 | </button> |
| 36 | ); |
| 37 | } |