π UserAuthService
A full-stack User Authentication Service built using Spring Boot for the backend and React for the frontend. This project provides secure user registration, login, and role-based access control using JWT authentication, making it suitable for modern and scalable web applications.
β¨ Features
- User Registration & Login
- JWT-based Authentication & Authorization
- Role-Based Access Control (RBAC)
- Secure Password Encryption (Spring Security)
- RESTful APIs
- React-based Frontend Integration
- CORS Configuration for FrontendβBackend Communication
π οΈ Tech Stack
- Backend
- Java
- Spring Boot
- Spring Security
- JWT (JSON Web Tokens)
- JPA / Hibernate
- MySQL
- Frontend
- React
- JavaScript
- Html
- Css
- React Router
π Project Structure UserAuthService/ βββ backend/ β βββ controller/ β βββ service/ β βββ repository/ β βββ model/ β βββ security/ β βββ application.properties β βββ frontend/ β βββ src/ β βββ components/ β βββ pages/ β βββ services/
βοΈ Backend Configuration (application.properties)
Before running the application, you must configure the following properties in application.properties.
1οΈβ£ Server Configuration server.port=8080 ( Change the port if required )
2οΈβ£ Database Configuration spring.datasource.url=jdbc:mysql://localhost:3306/userauthdb spring.datasource.username=YOUR_DB_USERNAME spring.datasource.password=YOUR_DB_PASSWORD
Create a MySQL database named userauthdb Replace username and password with your MySQL credentials
3οΈβ£ JPA / Hibernate Configuration spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=true spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
update automatically updates database tables show-sql prints SQL queries in the console
4οΈβ£ JWT Configuration jwt.secret=your_jwt_secret_key jwt.expiration=86400000
jwt.secret: Use a strong secret key jwt.expiration: Token validity in milliseconds (24 hours here)
5οΈβ£ CORS Configuration (if applicable) frontend.url=http://localhost:3000 ( Ensure this matches your React frontend URL )
cd Server
mvn spring-boot:run
Backend will start at: http://localhost:8080
cd client
npm install
npm start
Frontend will run at: http://localhost:3000
π API Endpoints Method Endpoint Description POST /api/auth/register Register new user POST /api/auth/login User login & JWT generation GET /api/user/profile Get logged-in user details
π Authentication Flow
- User registers or logs in via React UI
- Backend validates credentials
- JWT token is generated and returned
- Token is stored on the frontend
- Protected APIs require JWT in Authorization header
Authorization: Bearer <JWT_TOKEN>
π Future Improvements
Refresh Token Support OAuth2 (Google/GitHub Login) Docker Support
π€ Contributing Contributions are welcome! Feel free to fork this repository and submit a pull request.
β If you like this project, consider giving it a star on GitHub!