User API
Account settings
1 min readManage the authenticated user's account settings. Retrieve profile information, update full name, and access subscription status and usage limits.
Available Endpoints
| Method | Endpoint | Description |
|---|---|---|
GET | /api/user/me | Get current user profile |
PUT | /api/user/me | Update current user profile |
DELETE | /api/user/me | Delete user account |
GET | /api/user/me/export | Export user data |
GET | /api/user/me/login-history | Get login history |
Endpoints
/api/user/meGet current user profile
Retrieve the authenticated user's profile information including subscription status and credits.
user:readRequest
curl -X GET "http://localhost:3030/api/user/me" -H "Authorization: Bearer YOUR_ACCESS_TOKEN" -H "Content-Type: application/json"const response = await fetch("http://localhost:3030/api/user/me", {
method: "GET",
headers: {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content-Type": "application/json",
},
});
const data = await response.json();
console.log(data);Response 200
User profile retrieved successfully
{
"success": true,
"status": 200,
"code": "OK",
"message": "Operation completed successfully",
"data": {
"id": "507f1f77bcf86cd799439011",
"createdAt": "2024-01-01T00:00:00.000Z",
"updatedAt": "2024-01-15T10:30:00.000Z",
"email": "[email protected]",
"isVerified": true,
"verifiedAt": "2024-01-01T00:05:00.000Z",
"isActive": true,
"lastLoginAt": "2024-01-15T09:00:00.000Z",
"fullName": "John Doe",
"emailPreferences": {
"marketingOptOut": false
},
"twoFactorEnabled": true,
"organizationCount": 1,
"role": "user"
}
}Error Responses
401— Unauthorized - Invalid or missing authentication
{
"success": false,
"status": 401,
"code": "UNAUTHORIZED",
"message": "Authentication required"
}403— Forbidden - Insufficient permissions
{
"success": false,
"status": 403,
"code": "FORBIDDEN",
"message": "You do not have permission to perform this action"
}/api/user/meUpdate current user profile
Update the authenticated user's full name.
user:writeRequest
curl -X PUT "http://localhost:3030/api/user/me" -H "Authorization: Bearer YOUR_ACCESS_TOKEN" -H "Content-Type: application/json" -d '{"fullName":"John Doe"}'const response = await fetch("http://localhost:3030/api/user/me", {
method: "PUT",
headers: {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content-Type": "application/json",
},
body: JSON.stringify({
"fullName": "John Doe"
}),
});
const data = await response.json();
console.log(data);Body Parameters
| Name | Type | Description |
|---|---|---|
fullNamerequired | string | User full nameJohn Doe |
Response 200
User profile updated successfully
{
"success": true,
"status": 200,
"code": "OK",
"message": "Operation completed successfully",
"data": {
"id": "507f1f77bcf86cd799439011",
"createdAt": "2024-01-01T00:00:00.000Z",
"updatedAt": "2024-01-15T10:30:00.000Z",
"email": "[email protected]",
"isVerified": true,
"verifiedAt": "2024-01-01T00:05:00.000Z",
"isActive": true,
"lastLoginAt": "2024-01-15T09:00:00.000Z",
"fullName": "John Doe",
"emailPreferences": {
"marketingOptOut": false
},
"twoFactorEnabled": true,
"organizationCount": 1,
"role": "user"
}
}Error Responses
401— Unauthorized - Invalid or missing authentication
{
"success": false,
"status": 401,
"code": "UNAUTHORIZED",
"message": "Authentication required"
}403— Forbidden - Insufficient permissions
{
"success": false,
"status": 403,
"code": "FORBIDDEN",
"message": "You do not have permission to perform this action"
}/api/user/meDelete user account
Permanently delete the authenticated user's account and all associated data. Requires password confirmation.
user:writeRequest
curl -X DELETE "http://localhost:3030/api/user/me" -H "Authorization: Bearer YOUR_ACCESS_TOKEN" -H "Content-Type: application/json"const response = await fetch("http://localhost:3030/api/user/me", {
method: "DELETE",
headers: {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content-Type": "application/json",
},
});
const data = await response.json();
console.log(data);Body Parameters
| Name | Type | Description |
|---|---|---|
passwordrequired | string | Current password for account deletion confirmation |
Response 200
Account deleted successfully
{
"success": true,
"status": 200,
"code": "OK",
"message": "Operation completed successfully",
"data": {
"message": "string"
}
}Error Responses
401— Unauthorized - Invalid or missing authentication
{
"success": false,
"status": 401,
"code": "UNAUTHORIZED",
"message": "Authentication required"
}403— Forbidden - Insufficient permissions
{
"success": false,
"status": 403,
"code": "FORBIDDEN",
"message": "You do not have permission to perform this action"
}/api/user/me/exportExport user data
Export all user data for GDPR compliance. Returns a JSON file with all user data.
user:readRequest
curl -X GET "http://localhost:3030/api/user/me/export" -H "Authorization: Bearer YOUR_ACCESS_TOKEN" -H "Content-Type: application/json"const response = await fetch("http://localhost:3030/api/user/me/export", {
method: "GET",
headers: {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content-Type": "application/json",
},
});
const data = await response.json();
console.log(data);Response 200
User data exported successfully
{
"success": true,
"status": 200,
"code": "OK",
"message": "Operation completed successfully",
"data": {}
}Error Responses
401— Unauthorized - Invalid or missing authentication
{
"success": false,
"status": 401,
"code": "UNAUTHORIZED",
"message": "Authentication required"
}403— Forbidden - Insufficient permissions
{
"success": false,
"status": 403,
"code": "FORBIDDEN",
"message": "You do not have permission to perform this action"
}/api/user/me/login-historyGet login history
Get the authenticated user's login history.
user:readRequest
curl -X GET "http://localhost:3030/api/user/me/login-history" -H "Authorization: Bearer YOUR_ACCESS_TOKEN" -H "Content-Type: application/json"const response = await fetch("http://localhost:3030/api/user/me/login-history", {
method: "GET",
headers: {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content-Type": "application/json",
},
});
const data = await response.json();
console.log(data);Response 200
Login history retrieved successfully
{
"success": true,
"status": 200,
"code": "OK",
"message": "Operation completed successfully",
"data": [
{
"id": "507f1f77bcf86cd799439011",
"timestamp": "2024-01-15T10:30:00.000Z",
"action": "login",
"ipAddress": "192.168.1.1",
"userAgent": "Mozilla/5.0...",
"success": true,
"metadata": {}
}
]
}Error Responses
401— Unauthorized - Invalid or missing authentication
{
"success": false,
"status": 401,
"code": "UNAUTHORIZED",
"message": "Authentication required"
}403— Forbidden - Insufficient permissions
{
"success": false,
"status": 403,
"code": "FORBIDDEN",
"message": "You do not have permission to perform this action"
}