Skip to content
Init is coming / May 19 - 23
Back

Delete session by id fails: "User (role: guests) missing scope (account)"

  • 0
  • Auth
  • REST API
Belly
16 Apr, 2025, 19:04

I'm developing my Godot game using Apwwrite. I use Appwrite's REST API. I can login successfully and retrieve a session id but when I call delete session and attaching the session_id in the headers and endpoint I'm getting the following error: {"message":"User (role: guests) missing scope (account)","code":401,"type":"general_unauthorized_scope","version":"1.6.2"}

This is my function in GDScript: func logout(session_token: String) -> void: print("[UserNetwork] Attempting to delete all sessions")

TypeScript
var headers = [
    "X-Appwrite-Response-Format: 1.6.0",
    "X-Appwrite-Project: " + _PROJECT_ID,
    "Content-Type: application/json",
    "X-Appwrite-Session: " + session_token,
]

print("[UserNetwork] Headers for logout: ", headers)

var network_request = NetworkRequest.new()
network_request.set_url(_APPWRITE_ENDPOINT + "/account/sessions/" + session_token)
network_request.set_method(HTTPClient.METHOD_DELETE)
network_request.set_headers(headers)

var client = HTTPClient.new()
_network.execute(client, network_request, _on_logout_result)

func _on_logout_result(request_id: String, response_body, response_code, response_attached_params): print("[UserNetwork] Logout response received. Status code: ", response_code) print("[UserNetwork] Response body: ", response_body)

TypeScript
if response_code == 204:
    _session_id_changes.on_next("")
    _is_logged_in.Value = false
    print("[UserNetwork] Logout successful")
else:
    print("[UserNetwork] Logout failed with status code: ", response_code)

Basically I don't know how to make Appwrite recognize that the session id is associated with a valid user. Thanks in advance!

TL;DR
Developers trying to delete a session by ID in Godot using Appwrite's REST API are encountering a "User (role: guests) missing scope (account)" error. The issue lies in Appwrite not recognizing the session ID as belonging to a valid user. To resolve this, ensure that the user has the necessary permissions or scopes to perform the session deletion action.
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