© Angelo-Gabriel Barbu - angelo.barbu123@gmail.com - 2025
- Authentication-Module
- © Angelo-Gabriel Barbu - angelo.barbu123@gmail.com - 2025
- Table of Contents
- Project Overview
- Features
- Tech Stack
- Folder Structure
- Architecture
- Security
- Authentication Methods
- Forms & Validation
- Admin Dashboard
- User Dashboard
- Frontend Styling
- Setup Instructions
- Environment Variables
- Scripts
- Testing
- Deployment
- Planned Improvements
- License
A secure, full-featured authentication module supporting both traditional email/password login and Google OAuth. Includes user and admin dashboards, role-based access, password setting for Google users, and user management.
- JWT-based session management
- Google OAuth login
- Role-Based Access Control (RBAC)
- Admin user management (CRUD)
- Responsive form validations
- Set password for Google-registered users
- Rate limiting & Helmet for security
- Toast-based user feedback
- Frontend: React, React Router, React Toastify, Google Identity Services
- Backend: Node.js, Express, Sequelize (PostgreSQL), JWT
- Security: Helmet, express-rate-limit, bcrypt
backend/
│
├── config/ # Environment config loading
├── controllers/ # Business logic (auth, admin, Google OAuth)
├── middlewares/ # JWT and Role authentication
├── models/ # Sequelize models
├── routes/ # Express route definitions
├── scripts/ # Seed script for admin
├── utils/ # JWT & password helpers
├── .env # Backend environment variables
├── app.js # Express app setup
└── server.js # Server entry pointfrontend/
│
├── public/
├── src/
│ ├── components/ # Shared components (Forms, Dashboards)
│ ├── pages/ # Page views (Login, Register)
│ ├── api.js # Axios instance with JWT
│ ├── AppRoutes.jsx # Protected routing logic
│ ├── styles.css # App-wide styling
│ └── App.js # Root component
└── .env # Frontend environment variablesThe backend follows a clean separation of concerns:
- Models: Sequelize models define data structure.
- Views: (Handled by React frontend)
- Controllers: Encapsulate business logic.
- Routes: Map HTTP endpoints to controllers.
- User roles are defined in the database (
user,admin) - Middleware checks access per route using JWT payload role.
- Regular users are routed to
/dashboard - Admin users are routed to
/admin - Admins can:
- View all users
- Create new users or admins
- Update or delete existing accounts
- Tokens issued upon login (or Google OAuth)
- Sent in
Authorizationheaders - Used to protect routes and manage sessions
app.use(helmet());Adds secure HTTP headers to protect from well-known web vulnerabilities.
app.use(rateLimit({ windowMs: 15 * 60 * 1000, max: 100 }));Mitigates brute-force attacks and abuse by limiting repeated requests.
- Register with required fields + password
- Login sets JWT token in
localStorage
- Login/registration via Google Identity Services
- Prompts user to optionally set password for manual login
- All forms have client-side validation
- Password confirmation fields in registration and update
- Error messages displayed via
toast.error()
- Create, update, delete users/admins
- View user list in a styled responsive table
- Edit form pre-filled with selected user
- View and update personal info
- Optional password change with validation
- Ability to delete account after confirming password
- Clean and modern design
- Uniform form components
- Responsive behavior with layout safety
cd backend
npm install
cp .env.example .env # Fill in DB, JWT_SECRET, etc.
npm run devcd frontend
npm install
cp .env.example .env # Include REACT_APP_API_BASE_URL, GOOGLE_CLIENT_ID
npm startBackend .env
DATABASE_URL=
PORT=
JWT_SECRET=
TOKEN_EXPIRATION_SECONDS=
GOOGLE_CLIENT_ID=
Frontend .env
REACT_APP_API_BASE_URL=http://localhost:5001/api
REACT_APP_GOOGLE_CLIENT_ID=<your_google_id>
seedAdmin.js: Seeds an initial admin user
node scripts/seedAdmin.jsThis repository ships with a zero-config, fully isolated test harness for both the Node/Express backend and the React frontend.
Follow the steps below (copy-paste friendly) and you will obtain deterministic test runs on any machine or CI runner.
Testing done using jest.
cd frontend/
npm ci
npm test
cd backend/
npm ci
npm testThis project uses Terraform to declaratively build and orchestrate a full-stack authentication system via Docker containers. It includes:
- PostgreSQL database [
auth-db] - Node.js REST API [
auth-api] - React.js frontend UI [
auth-ui]
cd infra/terraform
touch terraform.tfvars
# Example terraform.tfvars
# postgres_password = "your_postgres_password"
# jwt_secret = "your_jwt_secret"
# token_expiration_seconds = 3600
# google_client_id = "your_google_oauth_client_id"
# Remove node_modules & package-lock.json from backend/ and frontend/
terraform init
terraform apply
# Stopping the containers
terraform destroyTerraform will:
- Build docker images for the backend and frontend
- Pull the official PostgreSQL image
- Create a shared Docker network [
auth-network] - Start containers for the database, API and UI
- Better handling for the refresh token
- Email confirmation after registration
- Forgot password flow
- 2FA (Two-Factor Authentication)
- Dark mode UI theme
- Better beployment strategy
- Low-level & high-level architecture diagrams
- Better unit tests & e2e testing
- UI refinement overall
This project is licensed under the MIT License.