springboot-react-basic-auth

The goal of this project is to implement an application called book-app to manage books. For it, we will implement a back-end Spring Boot application called book-api and a front-end React application called book-ui. Besides, we will use Basic Authentication to secure both applications.
Proof-of-Concepts & Articles
On ivangfr.github.io, I have compiled my Proof-of-Concepts (PoCs) and articles. You can easily search for the technology you are interested in by using the filter. Who knows, perhaps I have already implemented a PoC or written an article about what you are looking for.
Additional Readings
Project Overview

Applications
-
book-api
Spring Boot Web Java backend application that exposes a Rest API to create, retrieve and delete books. If a user has ADMIN role he/she can also retrieve information of other users or delete them.
The application’s secured endpoints can only be accessed if a user has valid credentials (username and password) and has authorization roles for it.
book-api stores its data in a Postgres database.
book-api has the following endpoints:
| Endpoint |
Secured |
Roles |
POST /auth/authenticate -d {"username","password"} |
No |
|
POST /auth/signup -d {"username","password","name","email"} |
No |
|
GET /public/numberOfUsers |
No |
|
GET /public/numberOfBooks |
No |
|
GET /api/users/me |
Yes |
ADMIN, USER |
GET /api/users |
Yes |
ADMIN |
GET /api/users/{username} |
Yes |
ADMIN |
DELETE /api/users/{username} |
Yes |
ADMIN |
GET /api/books [?text] |
Yes |
ADMIN, USER |
POST /api/books -d {"isbn","title"} |
Yes |
ADMIN |
DELETE /api/books/{isbn} |
Yes |
ADMIN |
-
book-ui
React frontend application where a user with role USER can retrieve the information of a specific book or a list of books. On the other hand, a user with role ADMIN has access to all secured endpoints.
To log in, a user or admin must provide valid username and password credentials. book-ui communicates with book-api to get books and users data.
book-ui uses Mantine as a UI component library, with Tabler Icons for icons.
Prerequisites
npm
Java 25 or higher;
- A containerization tool (e.g.,
Docker, Podman, etc.)
Bash 4.0 or higher (macOS ships with Bash 3.2; install via brew install bash)
Start Environment
-
In a terminal, make sure you are inside the springboot-react-basic-auth root folder;
-
Run the following command to start docker compose containers:
docker compose up -d
Running book-app using Maven & Npm
-
book-api
-
Open a terminal and navigate to the springboot-react-basic-auth/book-api folder;
-
Run the following Maven command to start the application:
./mvnw clean spring-boot:run
-
book-ui
-
Open another terminal and navigate to the springboot-react-basic-auth/book-ui folder;
-
Run the command below if you are running the application for the first time:
npm install
-
Run the npm command below to start the application:
npm start
Applications URLs
Note: the credentials shown in the table are the ones already pre-defined. You can signup new users.
Demo
Testing book-api Endpoints
Util Commands
Shutdown
-
To stop book-api and book-ui, go to the terminals where they are running and press Ctrl+C;
-
To stop and remove Docker Compose containers, network, and volumes, go to a terminal and, inside the springboot-react-basic-auth root folder, run the command below:
docker compose down -v
Running Tests
How to upgrade book-ui dependencies to latest version
-
In a terminal, make sure you are in the springboot-react-basic-auth/book-ui folder;
-
Run the following commands:
npm upgrade
npm i -g npm-check-updates
ncu -u
npm install
-
Spring Boot module (book-api): Code is formatted using Spotless with Google Java Format.
To check or apply formatting, make sure you are inside the module folder and run the following command:
-
Check formatting:
./mvnw spotless:check
-
Auto-fix formatting:
./mvnw spotless:apply
-
React module (book-ui): Code is formatted using Prettier with rules aligned to the project’s style guide (2-space indentation, single quotes, no trailing semicolons). ESLint conflicts are resolved via eslint-config-prettier. Configuration is defined in .prettierrc (formatting rules) and .editorconfig (editor consistency).
To check or apply formatting, make sure you are inside the book-ui folder and run the following commands:
-
Check formatting:
npm run format:check
-
Auto-fix formatting:
npm run format
How to optimize GIFs and PNGs in documentation folder
[Medium]: How I Reduce GIF and Screenshot Sizes for My Technical Articles on macOS
Support
If you find this useful, consider buying me a coffee:

License
This project is licensed under the MIT License.
References
评论