'use client'; import { useState } from 'react'; import { toast } from 'sonner'; import { Loader2, LogOut } from 'lucide-react'; import { createClient } from '@/lib/supabase/client'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardHeader, CardTitle, CardDescription, } from '@/components/ui/card'; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter, } from '@/components/ui/dialog'; export function SessionsCard() { const supabase = createClient(); const [open, setOpen] = useState(false); const [signingOut, setSigningOut] = useState(false); const onConfirm = async () => { setSigningOut(true); try { // scope: 'global' revokes every refresh token for this user // across all devices; the next auth-state change on this tab // triggers the usual redirect. const { error } = await supabase.auth.signOut({ scope: 'global' }); if (error) { toast.error(`Sign-out failed: ${error.message}`); return; } window.location.href = '/login'; } catch (err) { const msg = err instanceof Error ? err.message : 'Unknown error'; toast.error(msg); } finally { setSigningOut(false); } }; return ( <> Active sessions Sign out of every device where you're logged in — including this one. Useful if you lost a laptop or shared your password. Sign out everywhere? Every device logged into this account will be signed out and will need to log in again. You will be redirected to the login page. ); }