GET /users/me
GET /users/me
GET /api/users/me - Get current user's profile Verify authentication with Clerk Use service role client to bypass RLS Fetch profile using clerk_user_id Check for schema cache errors Fetch user permissions if profile exists If profile doesn't exist, try to find by email first, then create if needed Get full user info from Clerk Extract email from Clerk user Try to find profile by email (in case clerk_user_id is NULL) Check for schema cache errors Profile exists but doesn't have clerk_user_id set - update it Use existing tenant_id from the profile (skip tenant validation) Update name fields if missing Continue with creation attempt below Fetch permissions for the updated profile Generate UUID for the user_profile Check for pending invitations for this email Extract tenant_id from public_metadata if provided Verify tenant exists, but don't fail if table is not accessible (schema cache issue) If tenant lookup fails due to schema cache (PGRST205), skip validation for development Continue with tenant_id from DEFAULT_TENANT_ID - assume it's valid Try to find any tenant (for development) If still can't access tenants table, use the DEFAULT_TENANT_ID anyway Continue with tenantId as-is - don't fail In development, allow continuing with DEFAULT_TENANT_ID instead of failing Don't return error - continue with DEFAULT_TENANT_ID Check if profile with this email already exists (might have different clerk_user_id) Note: We already checked earlier, but if update failed, we check again here Check for schema cache errors If profile already has a different clerk_user_id, that's a conflict Profile exists with this email - update it with the clerk_user_id if not set CRITICAL: Only update fields if they're not already set or if we have better data PRESERVE existing admin role - never downgrade from admin to learner CRITICAL: Preserve existing admin/instructor roles - NEVER downgrade Only update role if: 1. Existing role is 'learner' AND new role is higher (instructor/admin) - upgrade allowed 2. NEVER downgrade from admin/instructor to learner 3. If existing role is admin/instructor, preserve it regardless of calculated role Don't update role - keep existing admin role Don't update role - preserve instructor Upgrade from learner to instructor/admin is allowed Explicit role from invitation/Clerk metadata Check for schema cache errors Create new profile Check for schema cache errors Check for unique constraint violations Unique constraint violation - profile might exist with different lookup Mark invitation as used if found Fetch permissions for the profile Return profile with permissions Return profile with permissions
Endpoint
GET /users/me
Authentication
This endpoint requires authentication. Include your authentication token in the request headers.
Error Responses
| Status Code | Error Code | Description |
|---|---|---|
| 401 | HTTP_401 | Unauthorized |
| 500 | HTTP_500 | Internal Server Error |
| 404 | HTTP_404 | Not Found |
| 404 | HTTP_404 | Not Found |
| 500 | HTTP_500 | Internal Server Error |
| 500 | HTTP_500 | Internal Server Error |
| 409 | HTTP_409 | Error |
| 500 | HTTP_500 | Internal Server Error |
| 500 | HTTP_500 | Internal Server Error |
| 500 | HTTP_500 | Internal Server Error |
| 500 | HTTP_500 | Internal Server Error |
| 500 | HTTP_500 | Internal Server Error |
| 500 | HTTP_500 | Internal Server Error |
| 500 | HTTP_500 | Internal Server Error |
| 500 | HTTP_500 | Internal Server Error |
Example Request
curl -X GET "https://api.allurelms.com/users/me" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json"