Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
S

springboot-react-jwt-token

> 前端框架
Open source

The goal of this project is to implement an application called order-app to manage orders. For it, we will implement a back-end Spring Boot application called o

186 stars0 likes1 views
WebsiteGitHub

About

The goal of this project is to implement an application called order-app to manage orders. For it, we will implement a back-end Spring Boot application called o

springboot-react-jwt-token

The goal of this project is to implement an application called order-app to manage orders. For it, we will implement a back-end Spring Boot application called order-api and a front-end React application called order-ui. Besides, we will use JWT 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

  • [Medium] Implementing A Full Stack Web App Using Spring-Boot and React
  • [Medium] Implementing Social Login in a Spring Boot and React App
  • [Medium] Building a Web Chat with Social Login using Spring Boot: Introduction
  • [Medium] Building a Single Spring Boot App with Keycloak or Okta as IdP: Introduction

Project Overview

Applications

  • order-api

    Spring Boot Web Java backend application that exposes a Rest API to create, retrieve, and delete orders. If a user has the 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 valid JWT access token is provided.

    order-api stores its data in Postgres database.

    order-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/numberOfOrders 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/orders [?text] Yes ADMIN
    POST /api/orders -d {"description"} Yes ADMIN, USER
    DELETE /api/orders/{id} Yes ADMIN
  • order-ui

    React frontend application where a user with role USER can create an order and retrieve a specific order. On the other hand, a user with role ADMIN as access to all secured endpoints.

    In order to access the application, a user or admin must log in using his/her username and password. All the requests coming from order-ui to secured endpoints in order-api include the JWT access token. This token is generated when the user or admin logs in.

    order-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)
  • jq

Start Environment

  • In a terminal, make sure you are inside the springboot-react-jwt-token root folder;

  • Run the following command to start Docker Compose containers:

    bash
    docker compose up -d

Running order-app using Maven & Npm

  • order-api

    • Open a terminal and navigate to the springboot-react-jwt-token/order-api folder;

    • Run the following Maven command to start the application:

      bash
      ./mvnw clean spring-boot:run
  • order-ui

    • Open another terminal and navigate to the springboot-react-jwt-token/order-ui folder;

    • Run the command below if you are running the application for the first time:

      bash
      npm install
    • Run the npm command below to start the application:

      bash
      npm start

Running Tests

  • order-api

    • Open a terminal and navigate to the springboot-react-jwt-token/order-api folder;

    • Run all tests:

      bash
      ./mvnw clean test
  • order-ui

    • Open a terminal and navigate to the springboot-react-jwt-token/order-ui folder;

    • Run all tests:

      bash
      npm test

Applications URLs

Application URL Credentials
order-api http://localhost:8080/swagger-ui.html
order-ui http://localhost:3000 admin/admin, user/user or signing up a new user

Note: the credentials shown in the table are the ones already pre-defined. You can signup new users.

Demo

  • The gif below shows a user loging in:

  • The gif below shows an admin loging in:

Testing order-api Endpoints

  • Manual Endpoints Test using Swagger

    • Open a browser and access http://localhost:8080/swagger-ui.html. All endpoints with the lock sign are secured. In order to access them, you need a valid JWT access token;

    • Click POST /auth/authenticate and then, click Try it out button;

    • Provide the user credentials username and password:

      json
      { "password": "user", "username": "user" }
    • Click the Execute button. It should return something like:

      Code: 200
      { "accessToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9..." }

      Note 1: You can use the admin credentials to access more secured endpoints.

      Note 2: The token will expire in 10 minutes.

    • Copy the accessToken value (without the double quotes);

    • Click the Authorize button at the top of the page;

    • In Value input field, paste the copied token;

    • Click the Authorize button and then, click the Close button;

    • To create an order, click POST /api/orders and then, click the Try it out button;

    • Provide the description of the order:

      json
      { "description": "Buy two iPhones" }
    • Click the Execute button. It should return something like:

      Code: 200
      {
        "id": "718c9f40-5c06-4571-bc3e-3f888c52eff2",
        "description": "Buy two iPhones",
        "user": { "username": "user" },
        "createdAt": "..."
      }
  • Manual Endpoints Test using curl

    • Open a terminal;

    • Call GET /public/numberOfUsers:

      bash
      curl -i localhost:8080/public/numberOfUsers

      It should return:

      HTTP/1.1 200
      2
    • Call GET /api/orders without JWT access token:

      bash
      curl -i localhost:8080/api/orders

      As for this endpoint a valid JWT access token is required, it should return:

      HTTP/1.1 401
    • Call POST /auth/authenticate to get the admin JWT access token:

      bash
      ADMIN_ACCESS_TOKEN="$(curl -s -X POST http://localhost:8080/auth/authenticate \
        -H 'Content-Type: application/json' \
        -d '{"username": "admin", "password": "admin"}' | jq -r .accessToken)"
      echo $ADMIN_ACCESS_TOKEN
    • Call GET /api/orders again, now with the admin JWT access token:

      bash
      curl -i -H "Authorization: Bearer $ADMIN_ACCESS_TOKEN" localhost:8080/api/orders

      It should return an empty array or an array with orders:

      HTTP/1.1 200
      [ ... ]
    • Call GET /api/users/me to get more information about the admin:

      bash
      curl -i -H "Authorization: Bearer $ADMIN_ACCESS_TOKEN" localhost:8080/api/users/me

      It should return:

      HTTP/1.1 200
      {
        "id": 1, "username": "admin", "name": "Admin", "email": "[email protected]", "role": "ADMIN",
        "orders": []
      }
  • Automatic Endpoints Test

    • Open a terminal and make sure you are in the springboot-react-jwt-token root folder;

    • Run the following script:

      bash
      ./order-api/test-endpoints.sh

      It should return something like the output below, where it shows the http code for different requests:

…

Util Commands

  • Postgres

    bash
    docker exec -it postgres psql -U postgres -d orderdb
    \dt
  • jwt.io

    With jwt.io, you can input the JWT token, and the online tool decodes the token, showing its header and payload.

Shutdown

  • To stop order-api and order-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-jwt-token root folder, run the command below:

    bash
    docker compose down -v

How to upgrade order-ui dependencies to latest version

  • In a terminal, make sure you are in the springboot-react-jwt-token/order-ui folder;

  • Run the following commands:

    bash
    npm upgrade
    npm i -g npm-check-updates
    ncu -u
    npm install

Code Formatting

  • Spring Boot module (order-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:

      bash
      ./mvnw spotless:check
    • Auto-fix formatting:

      bash
      ./mvnw spotless:apply
  • React module (order-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 order-ui folder and run the following commands:

    • Check formatting:

      bash
      npm run format:check
    • Auto-fix formatting:

      bash
      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

  • https://www.callicoder.com/spring-boot-security-oauth2-social-login-part-2/#jwt-token-provider-authenticat

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Javadockereslintjavajavascript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架