A microservice that handles user authentication including registration, login, and profile updates.
http://127.0.0.1:3001
Request:
- Method:
POST - Endpoint:
/auth/register - Content-Type:
application/json - Body:
{
"first_name": "John",
"last_name": "Doe",
"email": "john@example.com",
"password": "securepassword123"
}Response:
- Success (201):
{
"message": "User registered successfully"
}- Error (400):
{
"error": "Email already registered"
}Request:
- Method:
POST - Endpoint:
/auth/login - Content-Type:
application/json - Body:
{
"email": "john@example.com",
"password": "securepassword123"
}Response:
- Success (200):
{
"token": "eyJhbGciOiJIUzI1...",
"user": {
"user_id": 1,
"first_name": "John",
"last_name": "Doe",
"email": "john@example.com"
}
}- Error (401):
{
"error": "Invalid credentials"
}Request:
- Method:
PUT - Endpoint:
/auth/update-profile - Headers:
Authorization: Bearer <token>
- Content-Type:
application/json - Body:
{
"first_name": "John",
"last_name": "Smith",
"email": "john@example.com",
"old_password": "currentpassword",
"new_password": "newpassword123" // Optional
}Response:
- Success (200):
{
"message": "Profile updated successfully",
"user": {
"user_id": 1,
"first_name": "John",
"last_name": "Smith",
"email": "john@example.com"
}
}- Error (401):
{
"error": "Current password is incorrect"
}Here's how to make requests to the microservice using Python's requests library:
import requests
BASE_URL = 'http://127.0.0.1:3001'
# Register a new user
response = requests.post(f'{BASE_URL}/auth/register', json={
"first_name": "John",
"last_name": "Doe",
"email": "john@example.com",
"password": "securepassword123"
})
# Login
response = requests.post(f'{BASE_URL}/auth/login', json={
"email": "john@example.com",
"password": "securepassword123"
})
token = response.json()['token']
# Update profile (requires auth token)
headers = {'Authorization': f'Bearer {token}'}
response = requests.put(
f'{BASE_URL}/auth/update-profile',
headers=headers,
json={
"first_name": "John",
"last_name": "Smith",
"email": "john@example.com",
"old_password": "securepassword123"
}
)sequenceDiagram
participant C as Client
participant A as Auth Service
participant DB as Database
%% Registration Flow
C->>+A: POST /auth/register
A->>DB: Check if email exists
DB-->>A: Result
A->>A: Hash password
A->>DB: Save user
A-->>-C: 201 Success / 400 Error
%% Login Flow
C->>+A: POST /auth/login
A->>DB: Get user by email
DB-->>A: User data
A->>A: Verify password
A->>A: Generate JWT
A-->>-C: 200 + Token / 401 Error
%% Update Profile Flow
C->>+A: PUT /auth/update-profile
Note over C,A: Include Bearer Token
A->>A: Verify JWT
A->>DB: Get user
DB-->>A: User data
A->>A: Verify old password
A->>DB: Update user data
A-->>-C: 200 Success / 401 Error
- Implemented for: Emmanuel Acheampong
- Status: Complete and functional
- Repository - teammate retrieves service from GitHub: [Github REPO]
- Clone the repository from GitHub
- Install dependencies:
pip install -r auth_service/app/requirements.txt- Set up environment variables in
.env:
DB_URL=postgresql://[username]:[password]@localhost:5432/[dbname]
SECRET_KEY=[your-secret-key]
- Run the service:
python auth_service/run.py- Available for support: 12-6PM EST on weekdays
- Contact methods:
- GitHub Issues
- Discord group chat
- Important: Please report any issues within 24 hours of encountering them
If you cannot access the microservice:
- Verify PostgreSQL is running and accessible
- Check environment variables are properly set
- Ensure port 3001 is available
- Contact me during support hours for immediate assistance
- Requires PostgreSQL database
- Python 3.12+ recommended
- Port 3001 must be available
- Assumes JWT token-based authentication
- Requires proper CORS configuration if accessing from different origin
If the microservice is completely inaccessible:
- Use the provided example responses to mock the API responses
- Implement basic local authentication as temporary solution
- Contact me immediately for emergency support and resolution timeline