This project is a robust authentication service that integrates a Rust backend (compiled as a Node.js native module using Neon bindings) with an Express.js server. It uses MongoDB for storing user information and JWT tokens for secure authentication.
- User Registration with password hashing (using
bcrypt
). - Secure Login with JWT generation.
- Protected routes using JWT verification middleware.
- MongoDB integration for persistent user data storage.
- URL:
/signup
- Method:
POST
- Request Body:
{ "name": "John Doe", "email": "john.doe@example.com", "username": "johndoe", "password": "securepassword" }
- Response:
- Success (201):
{ "message": "User registered successfully." }
- Failure (400 or 422):
{ "error": "Validation failed: <details>." }
- Success (201):
- URL:
/login
- Method:
POST
- Request Body:
{ "username": "johndoe", "password": "securepassword" }
- Response:
- Success (200):
{ "token": "<jwt-token>" }
- Failure (401):
{ "error": "Invalid username or password." }
- Success (200):
- URL:
/protected
- Method:
GET
- Headers:
{ "Authorization": "Bearer <jwt-token>" }
- Response:
- Success (200):
{ "message": "Access granted." }
- Failure (401):
{ "error": "Unauthorized." }
- Success (200):
Variable | Description | Default Value |
---|---|---|
MONGO_URI |
MongoDB connection string | mongodb://localhost:27017 |
DATABASE_NAME |
Database name for the project | auth_service |