right-from-bracketLogout

End a user session and invalidate the token.

circle-info

When to use: When the user signs out or you need to invalidate a session for security.

chevron-rightPrerequisiteshashtag
  • Completed Login

  • Have an access token to invalidate

5-Line Core

result = await gateway.logout(
    access_token=token.access_token,
    organization_id="default",
)
# Token is now invalid

Step-by-Step

1

Call Logout

result = await gateway.logout(
    access_token=token.access_token,
    organization_id="default",
)
2

Handle Result

if result.is_ok:
    print("Logged out successfully")
else:
    print(f"Logout failed: {result.error.message}")
3

Token is Invalid

# After logout, the token no longer works
validate_result = await gateway.validate_session(
    access_token=token.access_token,
    organization_id="default",
)
print(f"Token valid: {validate_result.is_ok}")  # False
4

Expected Output

Logged out successfully
Token valid: False
circle-check

Complete Example

Create logout.py:

Run it:

Expected output:

Common Pitfalls

Pitfall
Solution

Not clearing client token

Clear stored token after logout

Ignoring logout errors

Log errors but don't block user

Not logging out on security events

Logout when password changed, suspicious activity

Next Steps

Last updated

Was this helpful?