Back

User (role: guests) missing scope (account)

  • 0
  • Self Hosted
  • React Native
  • Auth
kar
20 Sep, 2024, 22:30

Hello, I have as setup Appwrite+FastAPI+ReactNative and I'm facing this message User (role: guests) missing scope (account) in my logout. Let me share the code:

TypeScript
class AppwriteClientManager:
    def __init__(self):
        self.client = Client()
        self.client.set_endpoint(os.getenv("APPWRITE_ENDPOINT"))
        self.client.set_project(os.getenv("APPWRITE_PROJECT_ID"))
        # Optional: Set the API key if needed for specific requests
        # self.client.set_key(os.getenv("APPWRITE_API_KEY"))

    def set_session(self, session_id: str):
        """Sets the session ID for the client"""
        self.client.set_session(session_id)

    def get_account_service(self):
        """Returns the Account service initialized with the client"""
        return Account(self.client)

And the route:

TypeScript
@router.post("/logout")
def logout(request: LogoutRequest):
    session_id = request.session_id

    log_debug(f"Logout endpoint called with session_id: {session_id}")

    manager = AppwriteClientManager()  # Initialize the client manager
    account = manager.get_account_service()  # Get the Account service
    
    try:
        # Attempt to delete the session using the session_id
        result = account.delete_session(session_id)
        log_debug(f"Logout Result: {result}")
        return {"status": "success", "message": "Logged out successfully"}
    
    except Exception as e:
        # Handle known Appwrite errors (invalid session, unauthorized access)
        error_message = str(e)
        
        log_error(f"Logout error: {error_message}")
        
        # Treat all known Appwrite exceptions as 401 Unauthorized
        raise HTTPException(status_code=401, detail=f"{error_message}")

I can create the session but when I try to do logout I have User (role: guests) missing scope (account) I cannot find any hint in the available documentation or discord that solves my issue, so any help is welcome. Thanks.

TL;DR
Developers are encountering the message 'User (role: guests) missing scope (account)' when trying to logout using Appwrite, FastAPI, and ReactNative. The issue arises from lacking account scope for guests. To fix this, ensure the guest role has the necessary account scope. The code seems correct, so adjusting the Appwrite roles and scopes should resolve the problem.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more