Get current authenticated user's data from JWT token
Required
100/hour
JSON
Retrieves the current authenticated user's profile data based on the JWT token provided in the Authorization header. This endpoint is useful for getting user information in single-page applications or when you need to verify the current user's details.
GET https://hub.regardingwork.com/api/auth/me
Header | Required | Description |
---|---|---|
Authorization |
Required | Bearer token with your access token |
Content-Type |
Optional | application/json |
curl -X GET https://hub.regardingwork.com/api/auth/me \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
-H "Content-Type: application/json"
{
"user": {
"id": 38,
"username": "janechen",
"email": "jane@example.com",
"bio": "Software developer and tech enthusiast",
"website_url": "https://janechen.dev",
"profile_photo_url": "https://hub.regardingwork.com/api/public/user/38/profile-photo/file",
"role": "USER",
"premium_tier": "BASIC",
"is_premium": false,
"created_at": "2024-12-05T10:30:00Z",
"updated_at": "2024-12-15T14:22:00Z"
}
}
Field | Type | Description |
---|---|---|
user.id |
integer | Unique user identifier |
user.username |
string | User's unique username |
user.email |
string | User's email address |
user.bio |
string|null | User's biography/description |
user.website_url |
string|null | User's personal website URL |
user.profile_photo_url |
string|null | Direct URL to user's profile photo |
user.role |
string | User role (USER, ADMIN, SUPERADMIN) |
user.premium_tier |
string | Premium subscription tier |
user.is_premium |
boolean | Whether user has active premium subscription |
user.created_at |
datetime | Account creation timestamp |
user.updated_at |
datetime | Last profile update timestamp |
Status | Error | Description |
---|---|---|
401 | Authorization header required | Missing Authorization header with Bearer token |
401 | Invalid token: Not enough segments | Malformed JWT token |
401 | Token has expired | JWT token is past expiration time |
401 | Token has been revoked | Token was blacklisted (user logged out) |
404 | User not found | Token valid but user account no longer exists |
{
"error": "Token has expired"
}
const getCurrentUser = async () => {
try {
const token = localStorage.getItem('access_token');
const response = await fetch('https://hub.regardingwork.com/api/auth/me', {
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
}
});
if (response.ok) {
const data = await response.json();
console.log('Current user:', data.user);
return data.user;
} else {
const error = await response.json();
console.error('Error:', error.error);
return null;
}
} catch (error) {
console.error('Network error:', error);
return null;
}
};
// Usage
const user = await getCurrentUser();
if (user) {
document.getElementById('username').textContent = user.username;
document.getElementById('email').textContent = user.email;
}
import requests
def get_current_user(access_token):
"""Get current user data from Hub"""
url = 'https://hub.regardingwork.com/api/auth/me'
headers = {
'Authorization': f'Bearer {access_token}',
'Content-Type': 'application/json'
}
try:
response = requests.get(url, headers=headers)
if response.status_code == 200:
data = response.json()
print('Current user:', data['user'])
return data['user']
else:
error = response.json()
print('Error:', error.get('error'))
return None
except requests.RequestException as e:
print('Network error:', e)
return None
# Usage
token = 'your_access_token_here'
user = get_current_user(token)
if user:
print(f"Welcome, {user['username']}!")
print(f"Email: {user['email']}")
# Get current user data
curl -X GET https://hub.regardingwork.com/api/auth/me \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
-H "Content-Type: application/json"
# Example with error handling
curl -X GET https://hub.regardingwork.com/api/auth/me \
-H "Authorization: Bearer your_token_here" \
-H "Content-Type: application/json" \
-w "\nHTTP Status: %{http_code}\n" \
-s