Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
26 lines
830 B
TypeScript
26 lines
830 B
TypeScript
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<void>((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<boolean> => {
|
|
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
|
|
}
|