Skip to content

Authentication

  1. Register a user: POST /auth/register
  2. Verify email: GET /auth/verify/:token (idempotent)
  3. Login: POST /auth/login
  4. Use returned accessToken as Bearer token.

Registration behavior:

  • New email: 201 with verification-required message.
  • Existing unverified email: 200 and verification email is resent.
  • Existing verified email: 409 conflict.

Verify behavior:

  • First valid token use: 200 -> Email verified successfully.
  • Repeated valid token use: 200 -> Email already verified. You can sign in.
  • Invalid/expired token: 404.
  1. Authenticate with JWT.
  2. Create/regenerate key: POST /auth/api-key/regenerate
  3. Use returned key in X-API-Key.

Behavior details:

  • X-API-Key is accepted on authMiddleware routes (for example: POST /urls, GET /urls/my-links, PATCH/DELETE /urls/:shortId, GET /auth/me, POST /auth/change-password, DELETE /auth/account).
  • GET /auth/api-key and POST /auth/api-key/regenerate are Bearer-only; X-API-Key returns 401 (Bearer token required).
  • POST /urls/public uses optional auth: invalid X-API-Key does not block anonymous creation.
Authorization: Bearer <token>

For API key auth:

X-API-Key: <api_key>
  • Issue: on successful POST /auth/login (or OAuth callback flow).
  • Expiration: JWT expires in 1 hour.
  • Rotation: obtain a new JWT by logging in again.
  • Revocation: no token blacklist currently; JWT invalidates on expiry. API keys can be rotated via POST /auth/api-key/regenerate (old key becomes unusable).
  • Missing/invalid/expired JWT.
  • Invalid API key.
  • User not verified.
  • Authenticated user lacks ownership/permission for target resource.
  • Registration with already used verified email.
  • Verification email provider is temporarily unavailable during registration.
  • Registration is rolled back (no partial account is kept).
  • POST /auth/forgot-password: always returns generic 200 message.
  • POST /auth/reset-password: returns 200 on success, 400 for invalid/expired token or invalid body.
  • Successful reset also sets isVerified = true and invalidates the reset token (one-time use).