User API
Overview
The User API exposes the authenticated user's own profile (read and update) and the public profile of any user by id. Responses are returned as raw JSON objects — there is no { success, data } envelope.
Authentication Note
The /api/user/profile endpoints require an active session, authenticated by the NextAuth session cookie described in the Authentication API. Requests without a valid session receive a 401 Unauthorized. The public profile endpoint /api/user/{id} requires no authentication.
Endpoints
/api/user/profile
Description:Returns the full profile of the currently authenticated user. Requires a session. The user's email is excluded from the response.
Response: the user object (without email), for example:
{
"_id": "string",
"name": "string",
"bio": "string",
"website": "string",
"location": "string",
"image": "string",
"createdAt": "string"
}Example:
fetch('/api/user/profile', {
credentials: 'include'
})
.then(response => response.json())
.then(profile => console.log(profile))
.catch(error => console.error('Error:', error));/api/user/profile
Description:Updates the currently authenticated user's profile. Requires a session. Only the fields below may be changed; any other fields in the body are ignored.
Request Body: (all fields optional)
{
"name": "string",
"bio": "string",
"website": "string",
"location": "string"
}Response: the updated user object.
Example:
fetch('/api/user/profile', {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
body: JSON.stringify({
name: 'Jane Doe',
bio: 'Building laser-tag game modes',
website: 'https://example.com',
location: 'London, UK'
})
})
.then(response => response.json())
.then(profile => console.log('Updated', profile))
.catch(error => console.error('Error:', error));/api/user/{id}
Description: Returns the public profile of a user by id. No authentication required.
Path Parameters:
id— the user id (a MongoDB ObjectId).
Response:
{
"_id": "string",
"name": "string",
"bio": "string",
"website": "string",
"location": "string",
"image": "string",
"createdAt": "string"
}Example:
const userId = '64f0c0ffee0000000000abcd';
fetch(`/api/user/${userId}`)
.then(response => response.json())
.then(profile => console.log(profile))
.catch(error => console.error('Error:', error));Listing a User's Scripts
There is no per-user scripts endpoint under /api/user. To list the scripts a user owns, call the Scripts API with the authorid query parameter: GET /api/scripts?authorid={id}. See the Scripts API for details.