Authentication Overview
The MediGuide API uses a simple user ID-based authentication system. After successful login or signup, the client receives auserId which should be stored and included in subsequent requests that require user identification.
User Registration
Signup
Create a new user account.Unique username for the account
User’s email address (must be unique)
User’s password
Response (201)
Success message
Unique identifier for the newly created user
Username of the registered user
Error Responses
400 Bad Request - User or email already exists:User Login
Authenticate an existing user.User’s username
User’s password
Response (200)
Success message
User’s unique identifier (store this for authenticated requests)
Authenticated user’s username
Error Responses
401 Unauthorized - Invalid credentials:Password Recovery
Request Reset Code
Request a password reset code to be sent to the user’s email.Email address associated with the account
Response (200)
Success message
6-digit reset code (valid for 30 minutes)
Error Responses
404 Not Found - Email not found:Verify Reset Code
Verify the reset code before allowing password change.Email address associated with the account
6-digit reset code received from forgot-password endpoint
Response (200)
Success message
User ID associated with the verified reset code
Error Responses
401 Unauthorized - Invalid or expired code:Reset Password
Reset the user’s password using the verified reset code.Email address associated with the account
6-digit reset code received from forgot-password endpoint
New password (minimum 6 characters)
Response (200)
Success message
User’s unique identifier
User’s username
Error Responses
400 Bad Request - Invalid password:Session Management
Client-Side Storage
After successful login or signup, the client should store theuserId in localStorage for subsequent authenticated requests:
Using User ID in Requests
Include theuserId in request bodies or query parameters for endpoints that require user identification:
Security Considerations
Production Recommendations
For production deployment, consider implementing:- Password Hashing: Use bcrypt or similar to hash passwords before storage
- JWT Tokens: Implement token-based authentication instead of user ID in localStorage
- HTTPS: Always use HTTPS in production to encrypt data in transit
- Rate Limiting: Add rate limiting to prevent brute force attacks
- CORS Configuration: Configure CORS to allow only trusted origins
- Session Expiry: Implement session timeout and token refresh mechanisms
- Email Verification: Send actual emails for password reset instead of returning codes in response
Reset Code Security
- Reset codes are 6-digit random numbers
- Codes expire after 30 minutes
- Codes are invalidated after successful password reset
- Only one reset code is active per user at a time
