Registration and Login with React and Springboot
Table of Contents
- Custom Login and Registraion
- OAuth2 Login with Google
- Email Notification Generation on Custom Signup/Login using Java Mail Sender
- Customizable Email Template
- Phone notification on custom Signup/Login using Twilio
- Login with Google
- Email Notification
- Phone Notification
Backend is built using Java Springboot with Postgres DB. And frontend is built using React
- Strategy Design Pattern to implement different login strategies i.e. Custom Login/ Login using Google
- Event driven programming/Observer pattern is used to generate async email and mobile notifications without slowing down the main flow
- Liquibase is for Postgres DB change management to easily sync the changes if there are multiple db involved(i.e. dev, qa, prod)
- OAuth2 flow is used for Login via Google
If you want to understand how different components are communication with each other, you can view the detailed low level diagram below:
- Frontend requests the ID token from Google
- Google returns the ID token in the callback
- Frontend sends the ID token to the backend
- Backend validates the ID token received from the client
- Backend creates an account in the databse
- Backend generates a custom JWT
- Backend sends the custom JWT in the header to the client
- Client includes the JWT in the request header for API requests
- JWT filter validates the JWT in each client request header
Here's how OAuth2 flow works:
Below is an example of how you can setup the project locally.
This project contains third party integrations. You need to gnerate the relevant API keys and add them in the project
If you want to use this module, first you have to generate the Google OAuth2 credentials. Refer to this guide for assistance: Google OAuth Credentials. While configuring 'Authorized JavaScript origins' in the Google Developer Console's Credential settings, remember to add both http://localhost and http://localhost:3000. After generating the client id:
- Update <CLIENT_ID> in GoogleLogin.js with your Google client ID in the React app
- Also replace with your client id in the application.properties in the Springboot app
app.googleClientId=<GOOGLE-CLIENT-ID>
To send messages on phone numbers, you need to configure Twilio account. Follow this guide for reference: Twilio SMS After creating the account, you will get a Twilio number, sid and token, add them to the application.properties in the Springboot app
twilio.sms.sender=<TWILIO-GENERATED-NUMBER>
twilio.sid=<TWILIO-SID>
twilio.token=<TWILIO-TOKEN>
If you want to send email notifications using your Google account (i.e. maleehakdev@gmail.com), you need to enable 2 factor authentication on your Gmail account and create a app password. For more information, visit Google docs. Once you get the app password, place it in the application.properties in the Springboot app
spring.mail.password=<YOUR_PASSWORD>
Use this website to generate the JWT secret key and place it in the application.properties in the Springboot app
security.jwt.secret-key=<SECRET-KEY>
- Install and setup Java 11 on your system
- Clone the repo
git clone https://github.com/Maleehak/login-template.git
- Run the below command to start up the backend application:
mvn clean install mvn spring-boot:run
- Install NPM packages
npm install
- Point the application to local backend server to call the APIs
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the MIT License. See LICENSE.txt for more information.




