'use client' import { useState } from 'react' import { useSearchParams } from 'next/navigation' import { Button } from '@/components/ui/button' import { BellOff, Check, Link2 } from 'lucide-react' import Link from 'next/link' import { toast } from 'sonner' // The token in the link IS the credential (HMAC-signed user id, issued only // in mail to the owner's own address). The page never needs a session; the // Go endpoint validates the token and disables email notification channels // plus self-addressed agent email tasks. Transactional mail (password // resets) keeps flowing — the copy must say so. export function UnsubscribeClient() { const params = useSearchParams() const token = params.get('token') ?? '' const [loading, setLoading] = useState(false) const [done, setDone] = useState(false) const [invalid, setInvalid] = useState(false) const handleUnsubscribe = async () => { setLoading(true) try { const res = await fetch('/api/notifications/unsubscribe', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ token }), }) const data = await res.json().catch(() => null) if (res.ok && data?.ok) { setDone(true) } else if (res.status === 400) { setInvalid(true) } else { toast.error(data?.error ?? 'Could not unsubscribe right now') } } catch { toast.error('Could not unsubscribe right now') } setLoading(false) } if (!token || invalid) { return (
This unsubscribe link is invalid or has expired. Open Settings → Notifications in the app to manage your email preferences directly.
Email preferences {' · '} Help center {' · '} Back to sign in
Notification emails and automations that email you have been turned off. You can re-enable them anytime in Settings → Notifications. Account emails such as password resets are not affected.
Email preferences {' · '} Help center {' · '} Back to sign in
Stop notification emails and automations that email you. Password resets and other account emails keep working, and you can re-enable notifications anytime in Settings.
Help center