import { LOGOUT } from '@/services/auth' export { expireRefreshSessionOnThisOrigin } from '@/lib/expireRefreshSession' /** First attempt is immediate; later attempts wait these delays. */ export const LOGOUT_RETRY_DELAYS_MS = [0, 150, 400] as const const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)) /** * Best-effort Nest logout. Retries transient failures so the DB session is * revoked when the API is only briefly unavailable. Persistent 5xx still * fails — the caller must then expire the httpOnly cookie locally. */ export const attemptServerLogout = async (): Promise => { for (const delay of LOGOUT_RETRY_DELAYS_MS) { if (delay > 0) await wait(delay) const result = await LOGOUT({ errorMode: 'silent' }) if (result.ok) return true } return false }