Logout flow
Authentication · Logout flow
It is important to read the sections Why this shape and Reference example and production readiness on Authentication before relying on this page. They explain why the default BFF-centred pattern exists, how you can extend or replace it, and what the reference implementation does and does not promise for production.
This page describes logout: the BFF asks the auth integration to revoke tokens when it can, clears auth cookies, and removes all cart and wishlist ID cookies the BFF manages. CSRF is required, and a successful response runs CsrfTokenCleanupInterceptor. Contract: logout.ts.
Logout process
-
CSRF token — Same as Login flow.
-
Logout request —
POST /auth/logoutwith CSRF header and cookie. -
CSRF validation — Same as login.
-
Token revocation — The BFF reads tokens from cookies and asks the auth provider to revoke access and refresh tokens in parallel—for example
logout.service.tsin the referencecommercetools-authpackage usesPromise.allSettledso one failure does not block the other. Local cleanup still runs if revocation fails. -
Cookie cleanup —
AuthService.logoutclears auth tokens and removes all cart ID and wishlist ID cookies. The controller does not wrap this route withhandleAuthWithCartSetup(used on Login flow and Register flow); teardown stays inAuthService.logout. -
Response — The BFF returns success; the presentation app updates the UI. The call is idempotent (it can succeed even when no tokens are present).
Error handling
- Missing tokens — Logout still completes and cookies are cleared.
- Revocation errors — Errors are logged; local session data is cleared anyway.