Overview
This service is the owner of two collections: users and watch progress.
It is not exposed to the internet directly — the Mecca API gateway forwards
/api/auth/* and /api/progress to it.
| Gateway route | Service route |
|---|---|
POST /api/auth/register | POST /users/register |
POST /api/auth/login | POST /users/login |
POST|GET /api/progress | POST|GET /progress |
Endpoints
Users
Create a user. The password is hashed with bcrypt before it is stored.
{
"username": "gaurav",
"email": "[email protected]",
"password": "••••••••"
}
201 Created
{ "message": "user created", "id": "..." }
| Status | Body |
|---|---|
400 | {"error": "username required"} (or email / password) |
409 | {"error": "username already exists"} |
Verify credentials and issue a JWT. The token's sub is the username and it expires after 24 hours.
{
"username": "gaurav",
"password": "••••••••"
}
200 OK
{ "token": "eyJhbGciOi..." }
| Status | Body |
|---|---|
401 | {"error": "invalid credentials"} |
Watch progress
Every progress route needs Authorization: Bearer <token>; the user comes from the token, never from the body.
Upsert the position for one episode. If finished is sent it wins; otherwise the episode counts as finished once the position is close to the end.
{
"show": "One Piece",
"path": "Episode 01.mkv",
"position": 612.4,
"duration": 1420.0,
"finished": false
}
| Status | Body |
|---|---|
400 | {"error": "show and path required"} |
401 | {"error": "missing bearer token"} / invalid or expired token |
Latest watched episode per show.
All episodes watched in one show, newest first.
Running it
cargo build --release
PORT=... MONGODB_URI=... JWT_SECRET=... \
./target/release/user_auth_api
JWT_SECRET is required — the service refuses to start without it. CORS allows any origin.