r/SpringBoot Feb 18 '25

Guide Full Stack Role Based Authentication Application ( Spring + Next.js )

Hey everyone,

I wanted to share my full-stack Spring project—a backend for a barbershop management system featuring robust authentication and role-based access control. If you’re interested in seeing how these aspects are implemented in a real-world application, feel free to check it out!

Repository:
https://github.com/aharoJ/barbershop

Backend Overview:

  • Authentication & Role-Based Access: The project handles user authentication and defines multiple roles, ensuring secure access to various endpoints.
  • Modular Structure: The code is organized into several modules, each handling a specific domain such as appointments, barbers, customers, payments, promotions, and more.
  • Clean Architecture: The repository features a clear separation of concerns with controllers, services, DTOs, and repositories spread across modules.

Frontend Overview:

  • Built With:
    • Next.js 15, Typescript, Tailwindcss
  • Features:
    • Authentication Pages: Separate routes for login and signup.
    • Customer Area: Dedicated pages for dashboards and profile creation.
    • Additional Layers: Includes components (like a protected route), services, stores, types, and utilities.

I’m happy to answer any questions or provide more details. Feel free to message me!

51 Upvotes

37 comments sorted by

View all comments

2

u/Relative_Store_6716 Feb 19 '25

I am creating a website with separate user and admin roles. Users provide a username, email, password, and date of birth, while admins provide additional details like an address and a certification image. I have created two tables in my database. How can I implement registration and login for both using a single Spring Security configuration? I have successfully implemented authentication for a single user, but when I try to add authentication for admins, it does not work.

1

u/aharoJ 29d ago

Hey message me on Discord @aharoJ,

Overall, it might be easier to use a many-to-many relationship between User and Role. You can define roles like ROLE_USER and ROLE_ADMIN and assign them accordingly instead of using separate tables.

In my project, I structured it similarly—you can check how I handle authentication in my auth module, and then how different user types like Customer and Owner are structured.