-
Notifications
You must be signed in to change notification settings - Fork 491
Description
Labels: bug, authentication, self-hosted, invitation
Bug Summary
Invited users can successfully create accounts but receive 401 Unauthorized errors when attempting to access workspace resources, preventing them from joining the organization in Agenta OSS self-hosted deployments.
Steps to Reproduce
- Organization owner sends invitation via Agenta UI.
- User receives invitation email and clicks the invitation link.
- User successfully creates account (signup endpoint returns 200).
- User gets stuck on loading page with continuous 401 errors.
Expected Behavior
User should automatically join the workspace after accepting invitation and gain access to organization resources.
Actual Behavior
User encounters 401 Unauthorized errors for:
GET /api/profilePOST /api/organizations/{org_id}/workspaces/{workspace_id}/invite/acceptPOST /api/preview/tracing/spans/query- Other workspace-related API endpoints
Environment
- Agenta Version: Latest OSS (self-hosted)
- Deployment Method: Docker Compose
- Platform: ARM64 EC2 instance
- Database: PostgreSQL (containerized)
- Authentication: SuperTokens
###Error Logs
2025-11-04T05:41:51.995Z [INFO.] [scopes] user created [oss.src.services.user_service] user_id=None
172.18.0.7:39236 - "POST /api/auth/signup HTTP/1.1" 200
2025-11-04T05:41:52.256Z [ERROR] 401: Unauthorized [oss.src.services.auth_helper]
172.18.0.7:39238 - "POST /api/organizations/.../workspaces/.../invite/accept?project_id=... HTTP/1.1" 401
2025-11-04T05:41:52.464Z [ERROR] 401: Unauthorized [oss.src.services.auth_helper]
172.18.0.7:39238 - "GET /api/profile HTTP/1.1" 401Root Cause Analysis
The invitation acceptance process fails to properly associate new users with the organization in Agenta's core database. While users are successfully created in the SuperTokens authentication system, they lack the necessary organization membership records in the core database, resulting in authorization failures.
Impact
- Prevents scaling user invitations as manual database intervention is required for each new user.
- Breaks the standard user onboarding flow.
- Affects team collaboration features.
Additional Context
- First and second invited users work correctly.
- Issue appears consistently from the third user onwards.
- SuperTokens service is functioning correctly.
- Database permissions are properly configured.
Temporary Solution
Create this script to automatically fix new users:
#!/bin/bash
# Configuration - Update these values for your deployment
ORG_ID="019a4d38-7705-7ec2-8173-514d7cf51cba" # Replace with your organization ID
POSTGRES_CONTAINER="agenta-oss-gh-postgres-1"
echo "Fixing new user permissions..."
# Get the most recent user who might need fixing
LATEST_USER=$(docker exec -it $POSTGRES_CONTAINER psql -U agenta_user -d agenta_oss_core -t -c "
SELECT id FROM users
WHERE created_at > NOW() - INTERVAL '1 hour'
ORDER BY created_at DESC
LIMIT 1;
" | tr -d ' \n\r')
if [ -n "$LATEST_USER" ]; then
echo "Found recent user: $LATEST_USER"
# Temporarily make them organization owner to grant access
docker exec -it $POSTGRES_CONTAINER psql -U agenta_user -d agenta_oss_core -c "
UPDATE organizations
SET owner = '$LATEST_USER'
WHERE id = '$ORG_ID';
"
# Clean up any pending invitations for this user
docker exec -it $POSTGRES_CONTAINER psql -U agenta_user -d agenta_oss_core -c "
DELETE FROM project_invitations
WHERE organization_id = '$ORG_ID'
AND created_at > NOW() - INTERVAL '1 hour';
"
echo "User permissions fixed. They should now be able to access the workspace."
else
echo "No recent users found to fix."
fiUsage
- Update the ORG_ID variable with your organization ID.
- Make the script executable: chmod +x fix_new_users.sh.
- Run after each new user signup: ./fix_new_users.sh.
Alternative Manual Fix
- Connect to database:
docker exec -it agenta-oss-gh-postgres-1 psql -U agenta_user -d agenta_oss_core- Find the new user:
SELECT * FROM users ORDER BY created_at DESC LIMIT 3;- Make them organization owner (replace USER_ID and ORG_ID):
UPDATE organizations
SET owner = 'NEW_USER_ID'
WHERE id = 'YOUR_ORG_ID';4.. Clean up invitation:
DELETE FROM project_invitations
WHERE email = 'new_user_email@domain.com';