GET

/api/auth/me

Get current authenticated user's data from JWT token

Authentication

Required

Rate Limit

100/hour

Response

JSON

Description

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.

Use Cases
  • Profile pages - Display current user's information
  • Navigation bars - Show username and profile photo
  • Authorization checks - Verify user permissions and roles
  • User settings - Pre-populate forms with current data

Request

URL
GET https://hub.regardingwork.com/api/auth/me
Headers
Header Required Description
Authorization Required Bearer token with your access token
Content-Type Optional application/json
Example Request
curl -X GET https://hub.regardingwork.com/api/auth/me \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -H "Content-Type: application/json"

Success Response

200 OK - User data retrieved successfully
Response Body
{
  "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"
  }
}
Response Fields
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

Error Responses

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
Example Error Response
{
  "error": "Token has expired"
}

Code Examples

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

Security Notes

⚠️ Important Security Considerations
  • Token Storage: Store access tokens securely (httpOnly cookies recommended for web apps)
  • Token Validation: Always validate token expiration and handle refresh token logic
  • HTTPS Only: Only use this endpoint over HTTPS in production
  • Rate Limiting: Respect rate limits to avoid temporary blocks
  • Error Handling: Properly handle 401 errors to redirect users to login

Related Endpoints

Authentication
User Management