Skip to main content
This guide covers common authentication-related issues that may arise when working with the Definable backend.

JWT Token Issues

Symptoms:
  • Error: β€œInvalid or expired token”
  • Authentication works initially but fails after some time
  • Inconsistent authentication errors
Solutions:
  1. Check token expiration:
  2. Implement proper token refresh:
  3. Verify token format:
  4. Check JWT secret in environment:
    • Verify that JWT_SECRET environment variable is properly set
    • Ensure the same secret is used across all services/instances
    • Verify that it matches the value in your .env file
  5. Verify client settings for JWT expiration:
    • Definable’s JWT expiration is configured in the settings.py file
    • Default setting is jwt_expire_minutes
    • The token creation uses this setting:
Symptoms:
  • Error: β€œInvalid authorization” or β€œMissing authentication credentials”
  • Authentication works in some tools (e.g., Postman) but not in your code
Solutions:
  1. Check header format against JWTBearer implementation:
  2. Verify token inclusion in all requests:
  3. Check request object in JWTBearer middleware:
    • Definable’s JWTBearer middleware extracts token from either HTTP Request or WebSocket
    • For HTTP, it checks credentials.scheme == "Bearer"
    • For WebSocket, it checks websocket.query_params.get("token")
  4. Check for header modifications in proxies:
    • Some proxies may strip or modify authentication headers
    • Verify headers reach the API intact using debugging tools
Symptoms:
  • Unexpected logins from unknown locations
  • Security alerts about unauthorized access
  • Token becoming invalid unexpectedly
Solutions:
  1. Understand Definable’s token content:
  2. Implement client-side security measures:
  3. Configure JWT validity period:
    • Definable uses settings.jwt_expire_minutes to control token lifetime
    • Check your .env file and update JWT_EXPIRE_MINUTES to an appropriate value:
  4. Additional security for production:
    • Definable doesn’t include fingerprinting or IP validation by default
    • For production, consider implementing an enhanced authentication middleware:

RBAC Permission Issues

Symptoms:
  • Error: β€œAccess denied. Required: :” with status code 403
  • User can access some endpoints but not others
  • Permissions work for some users but not others
Solutions:
  1. Verify user roles in organization context:
  2. Understand Definable’s RBAC middleware:
    • Definable’s RBAC middleware checks for specific resource and action permissions
    • Routes are protected with: user: dict = Depends(RBAC("resource", "action"))
    • Permissions follow resource:action pattern, with wildcard support (*)
  3. Check organization membership status:
    • Definable’s RBAC checks OrganizationMemberModel.status == "active"
    • If user is not active in the organization, they’ll get 403 error
  4. Add missing permissions or update role:
  5. Debug Definable’s RBAC wildcard matching:
Symptoms:
  • User doesn’t see expected role in their profile
  • Role assignments don’t persist
  • User loses access after logging out and back in
Solutions:
  1. Verify role was correctly assigned in Definable’s database:
  2. Check role existence and permissions:
  3. Check for hierarchy level conflicts:
  4. Recreate role assignment:
Symptoms:
  • User with admin role cannot perform expected actions
  • Permissions don’t apply across organizations
  • Required org_id parameter missing errors
Solutions:
  1. Understand Definable’s organization-based permissions:
  2. Debug missing organization context:
  3. Verify permission scope in Definable:
  4. Handle multi-organization scenarios:

Login and Account Issues

Symptoms:
  • Unable to log in with valid credentials
  • Error message: β€œIncorrect username or password”
  • Persistent login failures
Solutions:
  1. Verify credentials against Definable’s auth service:
  2. Check password verification in Definable:
  3. Check for account status issues:
  4. Check for email verification requirements:
  5. Handle login lockouts:
Symptoms:
  • Cannot accept invitation
  • Error in signup process
  • Invitation links expired or invalid
Solutions:
  1. Verify invitation token:
  2. Debug invitation token issues:
  3. Resend invitation if needed:
  4. Complete signup with invitation:
Symptoms:
  • Cannot update profile information
  • Password reset fails
  • Email verification issues
Solutions:
  1. Debug password reset flow:
  2. Check email verification status:
  3. Update user profile:
  4. Handle account deletion:

WebSocket Authentication Issues

Symptoms:
  • WebSocket connection is rejected
  • Error: β€œNot authenticated” or β€œInvalid token”
  • Connection drops immediately after establishing
Solutions:
  1. Verify WebSocket connection with token:
  2. Debug WebSocket auth errors:
  3. Handle WebSocket reconnection with token refresh:
  4. Check RBAC permissions for WebSocket connections:

Next Steps

If you’ve resolved your authentication issues, consider reviewing these related guides: If you’re still experiencing authentication problems, check the API documentation or contact the development team for assistance.