Skip to main content
POST
/
api
/
v1
/
auth
/
verify-user
Verify User Exists
curl --request POST \
  --url https://api.example.com/api/v1/auth/verify-user
{
  "success": true,
  "exists": true,
  "message": "User verified and exists in database"
}
Verifies whether the authenticated user exists in the database. If the user is not found, this endpoint will initiate user creation in the Engine and Database Storage services.

Authentication

This endpoint requires authentication via JWT token in the Authorization header.
Authorization: Bearer <your_jwt_token>

Request Body

This endpoint does not accept a request body. The user ID and email are extracted from the JWT token.

Response

success
boolean
Indicates if the verification was successful
exists
boolean
Indicates if the user exists in the database
message
string
Description of the verification result

Examples

Successful Request (User Exists)

curl -X POST "http://localhost:8000/api/v1/auth/verify-user" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"
{
  "success": true,
  "exists": true,
  "message": "User verified and exists in database"
}

User Creation Flow

When a user is not found in the database:
{
  "error": "User not found in database and creation is in progress.",
  "exists": false
}

Error Responses

Error: No Token Provided

{
  "error": "No token provided."
}

Error: Invalid Token

{
  "error": "Invalid or expired token."
}

Error: Invalid Token Payload

{
  "error": "Invalid token payload."
}

Implementation Details

This endpoint performs the following operations:
  1. Token Validation: Verifies the JWT token and extracts user ID and email
  2. Database Check: Queries the PostgreSQL database for the user
  3. User Creation: If user not found, sends a message to Redis Streams to create the user
  4. Response Wait: Waits up to 5 seconds for the Engine to confirm user creation
  5. Verification: Checks the database again after creation attempt

User Creation Flow

Use Cases

Dashboard User Verification

Use this endpoint when a user navigates to the dashboard to ensure they exist in the system:
const ensureDashboardAccess = async (token) => {
  try {
    const result = await fetch('http://localhost:8000/api/v1/auth/verify-user', {
      method: 'POST',
      headers: { 'Authorization': `Bearer ${token}` }
    });
    
    const data = await result.json();
    
    if (data.success && data.exists) {
      // User exists, proceed to dashboard
      return { canAccess: true };
    } else if (!data.exists) {
      // User creation in progress, retry or show loading
      return { canAccess: false, reason: 'User creation in progress' };
    }
  } catch (error) {
    return { canAccess: false, reason: error.message };
  }
};

Build docs developers (and LLMs) love