Skip to content

Ban / Unban

Banning a user immediately invalidates all their tokens and prevents them from logging in.

await auth.ban_user(user_id)
await auth.ban_user(user_id)

This does three things atomically:

  1. Sets banned=True on the user record
  2. Bumps the token_version — all existing access tokens are rejected
  3. Revokes all refresh tokens — no new access tokens can be issued

The user is locked out immediately, even if they have a valid access token.

await auth.unban_user(user_id)
await auth.unban_user(user_id)

Sets banned=False. The user can log in again.

ActionResult
Login (email/password)403 Forbidden
Login (OAuth)403 Forbidden
Refresh tokenRejected
Access tokenRejected (token version mismatch)
IntrospectionReturns active: false

Access tokens are stateless JWTs — the server doesn’t check the database on every request. So how does banning work instantly?

Each access token contains a ver (token version) claim. When a user is banned, their token_version in the database is bumped. Any token with an older version is rejected.

For microservices using authfort-service with JWKS-only verification (no introspection), the ban takes effect when the access token expires (default: 15 minutes). To get instant invalidation in microservices, enable introspection.

Emits user_banned and user_unbanned events. See Events & Hooks for all events and their payloads.