Authentication API Documentation
This document provides documentation for the authentication endpoints available in the backend.
Authentication API Documentation
This document provides documentation for the authentication endpoints available in the backend. These endpoints handle social login via Steam, Google, and Discord, as well as user sessions and logout.
Base URL: /auth
🔐 Authentication Flow
The backend uses Passport.js for session-based authentication. It supports social login (Steam, Google, Discord) and local email/password authentication.
Initiate Login: The frontend redirects the user to the respective provider's endpoint (e.g.,
/auth/steam).Provider Redirect: The backend redirects the user to the social provider's login page.
Callback Handling: After a successful login, the provider redirects the user back to the backend's callback URL.
Session Creation: The backend authenticates the user, establishes a session, sets a
logged-incookie, and redirects the user back to theMAIN_URL(the frontend).Accessing Data: Subsequent requests from the frontend will include the session cookie, allowing access to protected routes or user data via
/auth/me.
🚀 Endpoints
1. GET /auth/steam
/auth/steamInitiates authentication via Steam.
Request
Method:
GETURL:
/auth/steamAuthentication: None required.
Response
Redirects: To the Steam OpenID login page. On failure, redirects to the
MAIN_URL.
2. GET /auth/google
/auth/googleInitiates authentication via Google.
Request
Method:
GETURL:
/auth/googleScope:
profile,emailAuthentication: None required.
Response
Redirects: To the Google OAuth2 login page. On failure, redirects to the
MAIN_URL.
3. GET /auth/discord
/auth/discordInitiates authentication via Discord.
Request
Method:
GETURL:
/auth/discordAuthentication: None required.
Response
Redirects: To the Discord OAuth2 login page. On failure, redirects to the
MAIN_URL.
4. GET /auth/logout
/auth/logoutLogs out the current user and terminates the session.
Request
Method:
GETURL:
/auth/logout
Response
Redirects: To the
MAIN_URLafter clearing the session.
5. GET /auth/me
/auth/meRetrieves the currently authenticated user's profile information.
Request
Method:
GETURL:
/auth/meAuthentication: Session cookie required for success.
Response
Status 200 (Success): Returns the user object.
Status 401 (Unauthorized): No active session. { "user": null }
6. POST /auth/register
/auth/registerRegisters a new user with email and password.
Request
Method:
POSTURL:
/auth/registerHeaders:
Content-Type: application/jsonBody:
Response
Status 201 (Created): Returns the newly created user object and starts a session.
Status 400 (Bad Request): Validation error or email already exists.
7. POST /auth/login
/auth/loginAuthenticates a user with email and password.
Request
Method:
POSTURL:
/auth/loginHeaders:
Content-Type: application/jsonBody:
Response
Status 200 (OK): Returns the user object and sets the session cookie.
Status 400 (Bad Request): Validation error or invalid credentials.
💡 Frontend Integration Example
[!NOTE] Ensure that the frontend application is configured to include credentials (cookies) in requests to the backend (e.g.,
credentials: 'include'in Fetch API).