Skip to content

User Auth App is a full-stack authentication system built using Java Spring Boot (backend), ReactJS (frontend), and PostgreSQL (database). This practice project focuses on implementing a secure JWT-based Authentication system, including access tokens, refresh tokens, role-based access control, and user profile management.

Notifications You must be signed in to change notification settings

Mahmud-Alam/spring-boot-userauth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

84 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ” User Auth App โ€“ Java Spring Boot with REST APIs, ReactJS, PostgreSQL

License: ISC Backend CI Frontend CI PostgreSQL


๐Ÿ“Œ Project Overview

User Auth App is a full-stack authentication system built using Java Spring Boot (backend), ReactJS (frontend), and PostgreSQL (database). This practice project focuses on implementing a secure JWT-based Authentication system, including access tokens, refresh tokens, role-based access control, and user profile management.

It provides a foundational structure for any application requiring user login, registration, token refresh, profile management, and admin-based user operations.


๐Ÿš€ Features

  • ๐Ÿ” JWT Authentication: Implements secure access and refresh token strategy.
  • ๐Ÿ“ User Registration & Login: Register new users and authenticate existing ones.
  • โ™ป๏ธ Token Refresh: Renew access token using refresh token seamlessly.
  • ๐Ÿ‘ค User Profile Management: Get, update profile info (only for logged-in users).
  • ๐Ÿง‘โ€๐Ÿ’ผ Admin Operations: Admins can manage all users (CRUD).
  • ๐ŸŒ Role-based Routing: Conditional rendering and routing based on roles.
  • โŒ 404 Page: User-friendly error page for invalid routes.
  • โ›” 403 Page: Unauthorized page shown when access is forbidden.

๐Ÿ› ๏ธ Tech Stack

Backend

  • ๐Ÿ”™ Java Spring Boot
  • Spring Security + JWT
  • Spring Data JPA
  • PostgreSQL
  • Swagger UI for API testing
  • Maven for dependency management

Frontend

  • ๐ŸŒ ReactJS
  • Axios for HTTP requests
  • React Router DOM
  • Context API (Auth state)
  • TailwindCSS for styling
  • React Toastify for alerts

Database


๐Ÿ“ธ Screenshots

๐Ÿ”„ Swagger API Flow

  1. All APIs Overview Swagger All APIs

  2. Login with user mahmud (get Access & Refresh Tokens) Login Token

  3. Authorize Swagger with Token Authorize Swagger

    Access Profile

  4. Access Protected /profile Endpoint Access Profile

  5. Admin Endpoint: All Users with Pagination (Page 1, 2 Users) All Users API

๐Ÿ’ป React Frontend

  1. Admin Dashboard Admin Dashboard

  2. User Profile Page User Profile

  3. Edit Profile Modal Edit Modal

  4. Login Page Login

  5. 403 Forbidden Page 403

  6. 404 Not Found Page 404


๐Ÿ—๏ธ Project Structure

๐Ÿ”™ Backend (Spring Boot)

spring-boot-userauth/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ main/
โ”‚   โ”‚   โ”œโ”€โ”€ java/com/mahmudalam/userauth/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ controller/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ service/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ repository/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ model/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ dto/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ security/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ UserAuthApplication.java
โ”‚   โ”‚   โ””โ”€โ”€ resources/
โ”‚   โ”‚       โ”œโ”€โ”€ application.properties
โ”‚   โ””โ”€โ”€ test/
โ”œโ”€โ”€ pom.xml

๐ŸŒ Frontend (React)

user-auth-frontend/
โ”œโ”€โ”€ public/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ api/
โ”‚   โ”œโ”€โ”€ pages/
โ”‚   โ”œโ”€โ”€ components/
โ”‚   โ”œโ”€โ”€ routes/
โ”‚   โ”œโ”€โ”€ contexts/
โ”‚   โ”œโ”€โ”€ App.jsx
โ”‚   โ””โ”€โ”€ main.jsx
โ”œโ”€โ”€ package.json

๐Ÿ”ง Installation & Setup

๐Ÿ“Œ Prerequisites

  • Java 21 LTS
  • Node.js & npm
  • PostgreSQL installed locally

๐Ÿ”ฝ Backend Setup

git clone https://github.com/Mahmud-Alam/spring-boot-userauth.git
cd spring-boot-userauth

๐Ÿงช Configure Database

Edit application.properties:

spring.application.name=userauth
server.port=8082

# PostgreSQL DB settings
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/bmudb
spring.datasource.username=postgres
spring.datasource.password=1234

# Hibernate / JPA settings
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect

# Spring Security
spring.security.user.name=mahmud
spring.security.user.password=mahmud

# Access/Refresh Token Secret
# Base64 encoded
# base64AccessSecretKeyMahmudAlamMahmudAlamMahmudAlam
# base64RefreshSecretKeyMahmudAlamMahmudAlamMahmudAlam
jwt.access.secret=YmFzZTY0QWNjZXNzU2VjcmV0S2V5TWFobXVkQWxhbU1haG11ZEFsYW1NYWhtdWRBbGFt
jwt.refresh.secret=YmFzZTY0UmVmcmVzaFNlY3JldEtleU1haG11ZEFsYW1NYWhtdWRBbGFtTWFobXVkQWxhbQ==
jwt.access.expiry=600000
jwt.refresh.expiry=1209600000

โ–ถ๏ธ Run the App

# Using Maven
mvn spring-boot:run

๐ŸŒ Frontend Setup

cd frontend
npm install
npm run dev

App runs on: http://localhost:5173

Create .env file:

VITE_API_BASE = "http://localhost:8082"

๐Ÿ“˜ API Endpoints

๐Ÿ” Authentication ( /api/auth )

Method Endpoint Description
POST /register Register new user
POST /login Login user, returns tokens
POST /refresh-token Refresh access token

๐Ÿ‘ค User ( /api/users )

Method Endpoint Access Role Description
GET /users ADMIN Get all users
GET /users/{id} ADMIN Get user by ID
POST /users ADMIN Create new user
PUT /users/{id} ADMIN Full update
PATCH /users/{id} ADMIN Partial update
GET /users/profile USER / ADMIN Get current user's profile
PUT /users/profile USER / ADMIN Full profile update
PATCH /users/profile USER / ADMIN Partial profile update

๐Ÿ”’ Security

  • ๐Ÿ” Passwords are hashed securely using Spring Security.
  • ๐Ÿงพ Role-based access control (ADMIN / USER).
  • โœ… JWT refresh & access token handling via HTTP-only headers/localStorage.
  • โ›” 401 & 403 responses handled gracefully on frontend.

๐Ÿงช Testing

mvn test

๐Ÿ”ฎ Future Improvements

  • Add account verification via email
  • Add password reset functionality
  • Rate limiting for login attempts
  • OAuth2 or social login support
  • Deploy to Render / Vercel / Railway

๐Ÿค Contributing

  1. Fork the project
  2. Create a new branch: git checkout -b feature/AmazingFeature
  3. Commit your changes: git commit -m 'Add some feature'
  4. Push to the branch: git push origin feature/AmazingFeature
  5. Open a Pull Request

๐Ÿ† Author

Mahmud Alam


๐Ÿ™ Acknowledgments

  • Thanks to the Spring Security and JWT communities
  • Inspired by modern authentication best practices

Happy coding! ๐Ÿ”๐Ÿš€

About

User Auth App is a full-stack authentication system built using Java Spring Boot (backend), ReactJS (frontend), and PostgreSQL (database). This practice project focuses on implementing a secure JWT-based Authentication system, including access tokens, refresh tokens, role-based access control, and user profile management.

Topics

Resources

Stars

Watchers

Forks

Languages