Skip to main content

Endpoint

GET /api/profile

Authentication

This endpoint requires authentication. Include a valid JWT token in the request headers.

Request Headers

Authorization
string
required
Bearer token obtained from login or Google authenticationFormat: Bearer <token>
Alternative:
x-auth-token
string
required
JWT token (without “Bearer” prefix)

Response

success
boolean
Always true for successful requests
user
object
User profile information

Example Request

cURL
curl -X GET http://localhost:3001/api/profile \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
JavaScript
const response = await fetch('http://localhost:3001/api/profile', {
  method: 'GET',
  headers: {
    'Authorization': `Bearer ${token}`
  }
});

const data = await response.json();
console.log(data.user);

Example Response

Success Response

200 OK
{
  "success": true,
  "user": {
    "id": "507f1f77bcf86cd799439011",
    "email": "[email protected]",
    "name": "John Doe",
    "profilePicture": "https://lh3.googleusercontent.com/a/...",
    "isGoogleUser": true
  }
}

Error Responses

Missing Token

401 Unauthorized
{
  "error": "No token provided"
}

Invalid Token

401 Unauthorized
{
  "error": "Invalid token"
}

Expired Token

401 Unauthorized
{
  "error": "Token expired"
}

User Not Found

404 Not Found
{
  "error": "User not found"
}

Use Cases

  • Profile Display: Fetch user information to display in the UI
  • Session Validation: Verify user is still authenticated
  • User Context: Get user details for personalized features
  • Account Settings: Pre-populate forms with current user data

Notes

This endpoint uses the same authentication middleware as /api/verify-token but returns more detailed user information including profile picture and OAuth status.
Cache the profile response on the client side to avoid repeated API calls. Refresh when the user updates their profile or after re-authentication.
  • Verify Token - Validate token without full profile data
  • Google Login - Initial authentication that returns user profile
  • Login - Standard login that returns JWT token

Build docs developers (and LLMs) love