appwrite.exception.AppwriteException: app.67735d03002b656bc8f1@service.cloud.appwrite.io (role: appl
- 0
- Auth
Hello Everyone i am using python
Hello Everyone i am using python
Database.py
settings = config()
client = Client()
client.set_endpoint(settings.get("APPWRITE", {}).get("ENDPOINT"))
client.set_project(settings.get("APPWRITE", {}).get("PROJECT_ID"))
client.set_key(settings.get("APPWRITE", {}).get("API_KEY_SECRET"))
# Initialize services
database_service = Databases(client)
users_service = Users(client)
account_service = Account(client)
messaging_service = Messaging(client)
teams_service = Teams(client)
strorage_service = Storage(client)
health_service = Health(client)
functions_service = Functions(client)
i am trying to get user session i have tried multiple stuff
First Try
Dashboard.py
@dashboard_bp.route("/dashboard", methods=["GET", "POST"])
def dashboard():
session_token = request.cookies.get("session")
if not session_token:
logging.warning("No session token found.")
return redirect(url_for("login_bp.login_page"))
print(account_service.get())
return "Hello"
Second Try:
current_dir = os.path.dirname(os.path.abspath(__file__))
template_dir = os.path.join(current_dir, "html")
dashboard_bp = Blueprint("dashboard_bp", __name__, template_folder=template_dir)
def decode_session_token(token):
"""Decodes a Base64-encoded, zlib-compressed session token."""
try:
parts = token.split(".")
if len(parts) < 2:
raise ValueError("Invalid session token format")
payload = parts[1] + "=" * (-len(parts[1]) % 4)
raw_decoded = base64.urlsafe_b64decode(payload)
decompressed = zlib.decompress(raw_decoded)
decoded_data = json.loads(decompressed.decode("utf-8"))
return decoded_data
except Exception as e:
logging.error(f"Error decoding session token: {e}")
return None
@dashboard_bp.route("/dashboard", methods=["GET", "POST"])
def dashboard():
session_token = request.cookies.get("session")
if not session_token:
logging.warning("No session token found.")
return redirect(url_for("login_bp.login_page"))
session_data = decode_session_token(session_token)
print(f"Decoded session data: {session_data}")
if not session_data or "userId" not in session_data or "$id" not in session_data["userId"]:
print.warning("Invalid session data.")
return redirect(url_for("login_bp.login_page"))
user_id = session_data["userId"]["$id"]
user_info = account_service.get(user_id=user_id)
print("User Info:" + user_info)
if not user_info:
logging.warning(f"No user found for ID {user_id}")
return redirect(url_for("login_bp.login_page"))
logging.info(f"User Info: {user_info}")
return jsonify(user_info) # Return user info as JSON
Where's your code for creating and storing the session?
And what are you calling that's throwing the exception.
And what's the full exception
app.67735d03002b656bc8f1@service.cloud.appwrite.io (role: applications) missing scope (account)
i am trying to get the user account using services_account.get()
the session is active and user is logged in
but i keep on getting the scope error when i have all scopes active for the api key
@Steven sorry for ping if you are here
full error logs here cause i do not have nitro
@login_bp.route("/user/login", methods=["GET", "POST"])
def login_page():
auth_3_enabled = False
if request.method == "POST":
username = request.form.get("email")
password = request.form.get("password")
user = authenticate_user(username, password)
if user:
return redirect(url_for("dashboard_bp.dashboard")) # Replace with actual dashboard route
else:
return render_template("LoginPage.html", error="Invalid username or password")
return render_template("LoginPage.html", auth_3_enabled=auth_3_enabled)
def authenticate_user(email, password):
try:
response = account_service.create_email_password_session(email=email, password=password)
if response:
log({"type": "info", "message": f"โ
[+] User {email} logged in successfully"})
return response
else:
log({"type": "warn", "message": f"โ [!] Invalid credentials for {email}"})
return None
except Exception as e:
log({"type": "error", "message": f"โ [-] Authentication failed for {email}: {e}"})
return None
Recommended threads
- Team Invitation URL
Hey everyone! ๐ I'm working on implementing team invitations in my Flutter app using a self-hosted Appwrite setup. I managed to send an email to the invitee u...
- Android - Appwrite self-host - Google OA...
I am having a *very* hard time getting my users authenticated using Google's OAuth2 and Appwrite. I am **self-hosting** on a personal server, let's call it `htt...
- I am looking for a US/Canada developer.