Skip to main content

Overview

The User Profile API allows you to retrieve and update user profile information including display name, email, and avatar settings.

Authentication

All user profile endpoints require authentication via Supabase Auth. Users can only access and modify their own profile information.
Authentication is handled through HTTP-only cookies. Ensure the user is logged in before making these requests.

Get Current User

/api/auth/me
Retrieves the current authenticated user’s profile information.

Response

user
object
required
The user profile object

Example Response

{
  "user": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "email": "[email protected]",
    "name": "Alex Student",
    "avatar_url": "https://example.com/avatar.jpg"
  }
}

Error Responses

error
string
Error message describing what went wrong
401 Unauthorized
{
  "error": "Not authenticated"
}
500 Internal Server Error
{
  "error": "Internal server error"
}

Get Full User Details

/api/auth/user
Retrieves detailed user information including username and profile data.

Response

id
string
required
Unique user identifier (UUID)
email
string
required
User’s email address
name
string
required
User’s full display name
username
string | undefined
User’s unique username if set
avatar_url
string | null
URL to user’s profile picture

Example Response

{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "email": "[email protected]",
  "name": "Alex Student",
  "username": "alexstudent",
  "avatar_url": "https://example.com/avatar.jpg"
}

Get Display Name

/api/auth/display-name
Retrieves the user’s display name and first name for personalization.

Response

displayName
string
required
User’s full display name
firstName
string
required
User’s first name extracted from full name
email
string
required
User’s email address

Example Response

{
  "displayName": "Alex Student",
  "firstName": "Alex",
  "email": "[email protected]"
}

Update Display Name

/api/auth/display-name
Updates the user’s display name in both the profiles and users tables.

Request Body

fullName
string
required
The user’s new full name (first and last name)

Example Request

{
  "fullName": "Alex Student"
}

Response

success
boolean
required
Indicates whether the update was successful
displayName
string
required
The updated display name
firstName
string
required
The extracted first name

Example Response

{
  "success": true,
  "displayName": "Alex Student",
  "firstName": "Alex"
}

Error Responses

400 Bad Request
{
  "error": "Full name is required"
}
401 Unauthorized
{
  "error": "Not authenticated"
}

Get User Stats

/api/dashboard/stats
Retrieves comprehensive user statistics including XP, level, streaks, and performance metrics.

Query Parameters

userId
string
required
The user ID to fetch statistics for

Response

totalXP
number
required
User’s total accumulated experience points
level
number
required
User’s current level (defaults to 1)
currentStreak
number
required
Current consecutive days of activity
longestStreak
number
required
Longest streak ever achieved
lastActivityDate
string
ISO timestamp of last activity
averageScore
number
required
Average score across all quizzes and flashcards (0-100)
totalQuizzes
number
required
Total number of quizzes completed
totalFlashcards
number
required
Total number of flashcard sessions completed
weeklyStudySessions
number
required
Number of study sessions in the past 7 days

Example Request

GET /api/dashboard/stats?userId=550e8400-e29b-41d4-a716-446655440000

Example Response

{
  "totalXP": 2450,
  "level": 5,
  "currentStreak": 7,
  "longestStreak": 14,
  "lastActivityDate": "2026-03-07T10:30:00Z",
  "averageScore": 87,
  "totalQuizzes": 23,
  "totalFlashcards": 15,
  "weeklyStudySessions": 12
}

Error Responses

400 Bad Request
{
  "error": "User ID required"
}
500 Internal Server Error
{
  "error": "Failed to fetch stats"
}

Build docs developers (and LLMs) love