|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import { Button } from '@/components/ui/button'; |
| 4 | +import { |
| 5 | + Dialog, |
| 6 | + DialogClose, |
| 7 | + DialogContent, |
| 8 | + DialogDescription, |
| 9 | + DialogFooter, |
| 10 | + DialogHeader, |
| 11 | + DialogTitle, |
| 12 | + DialogTrigger, |
| 13 | +} from '@/components/ui/dialog'; |
| 14 | +import { AlertTriangle, LogOut } from 'lucide-react'; |
| 15 | +import { useTRPC } from '@/lib/trpc/utils'; |
| 16 | +import { useMutation } from '@tanstack/react-query'; |
| 17 | +import { toast } from 'sonner'; |
| 18 | +import { signOut } from 'next-auth/react'; |
| 19 | + |
| 20 | +export function SignOutBrowserSessionsDialog() { |
| 21 | + const trpc = useTRPC(); |
| 22 | + |
| 23 | + const signOutBrowserSessionsMutation = useMutation( |
| 24 | + trpc.user.signOutBrowserSessions.mutationOptions({ |
| 25 | + onSuccess: async () => { |
| 26 | + toast.success('Browser sessions signed out. Redirecting to sign-in page...'); |
| 27 | + await signOut({ callbackUrl: '/users/sign_in' }); |
| 28 | + }, |
| 29 | + }) |
| 30 | + ); |
| 31 | + |
| 32 | + return ( |
| 33 | + <Dialog> |
| 34 | + <DialogTrigger asChild> |
| 35 | + <Button variant="outline" size="sm"> |
| 36 | + <LogOut className="mr-2 h-4 w-4" /> |
| 37 | + Sign Out Browser Sessions |
| 38 | + </Button> |
| 39 | + </DialogTrigger> |
| 40 | + <DialogContent className="sm:max-w-[425px]"> |
| 41 | + <DialogHeader> |
| 42 | + <DialogTitle className="flex items-center gap-2 text-orange-600"> |
| 43 | + <AlertTriangle className="h-5 w-5" /> |
| 44 | + Sign out all browser sessions? |
| 45 | + </DialogTitle> |
| 46 | + <DialogDescription className="text-muted-foreground pt-3"> |
| 47 | + This will sign you out of Kilo Code in every browser, including this one. CLI, VS Code, |
| 48 | + JetBrains, and other API tokens will continue to work. |
| 49 | + </DialogDescription> |
| 50 | + </DialogHeader> |
| 51 | + <DialogFooter className="gap-2 sm:gap-0"> |
| 52 | + <DialogClose asChild> |
| 53 | + <Button |
| 54 | + variant="secondary" |
| 55 | + className="w-full sm:w-auto" |
| 56 | + disabled={signOutBrowserSessionsMutation.isPending} |
| 57 | + > |
| 58 | + Cancel |
| 59 | + </Button> |
| 60 | + </DialogClose> |
| 61 | + <Button |
| 62 | + variant="destructive" |
| 63 | + className="w-full sm:w-auto" |
| 64 | + onClick={() => signOutBrowserSessionsMutation.mutate()} |
| 65 | + disabled={signOutBrowserSessionsMutation.isPending} |
| 66 | + > |
| 67 | + {signOutBrowserSessionsMutation.isPending |
| 68 | + ? 'Signing out...' |
| 69 | + : 'Sign Out Browser Sessions'} |
| 70 | + </Button> |
| 71 | + </DialogFooter> |
| 72 | + </DialogContent> |
| 73 | + </Dialog> |
| 74 | + ); |
| 75 | +} |
0 commit comments