Security and Access Control
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
Security and Access Control in the TAMV Online project encompasses the mechanisms used to authenticate users, authorize actions, and protect system resources. This module ensures that only registered and verified users can access specific functionalities within the "ambitious system," maintaining data integrity and privacy across the platform.
The system relies on a combination of token-based authentication and database-level role management to regulate traffic and identify sessions. This architecture supports the project's goal of providing a robust, single-developer scale application with professional security standards.
Sources: README.md:1-2, middleware/auth.js:1-5
Authentication Mechanisms
The authentication system is responsible for verifying user identities. It primarily uses JSON Web Tokens (JWT) to maintain stateless sessions between the client and the server.
User Registration and Login
Users must provide credentials that are matched against the encrypted records in the database. Upon successful validation, the system generates a token that must be included in the header of subsequent requests.
The flow above illustrates the initial handshake where a user exchanges valid credentials for an access token.
Sources: controllers/authController.js:10-45, database/schema.sql:12-20
Authorization and Middleware
Authorization is handled via middleware functions that intercept requests to protected routes. This ensures that the requester has the necessary permissions to execute the desired operation.
JWT Verification Middleware
The auth.js middleware extracts the token from the Authorization header, verifies its signature, and attaches the user payload to the request object. If the token is missing or invalid, the request is terminated before reaching the controller.
| Component | Description | Location |
|---|---|---|
verifyToken | Validates the JWT signature and expiration. | middleware/auth.js |
checkRole | Verifies if the authenticated user has specific permissions. | middleware/auth.js |
userRoutes | Defines endpoints that require prior authentication. | routes/userRoutes.js |
Sources: middleware/auth.js:15-30, routes/userRoutes.js:5-15
Data Security and Schema
The database schema includes specific constraints and fields dedicated to securing user information. Passwords are not stored in plain text, and specific flags are used to manage account status.
Security-Related Table Fields
The following fields in the users table are critical for access control:
| Field | Type | Description |
|---|---|---|
id | UUID/INT | Unique identifier for session linking. |
password_hash | VARCHAR | Encrypted representation of the user password. |
role | ENUM/VARCHAR | Defines user privileges (e.g., admin, user). |
is_active | BOOLEAN | Indicates if the account is permitted to log in. |
The ER diagram shows the relationship between a user entity and the sessions generated through the authentication process.
Sources: database/schema.sql:5-25, controllers/authController.js:50-60
Conclusion
The Security and Access Control system of TAMV Online provides a structured approach to identity management and resource protection. By utilizing JWT-based middleware and secure database schemas, the project ensures that its high-level objectives are met within a secure environment.
Sources: README.md:1-2, middleware/auth.js:1-10