Yesterday, I began working on the Email Verification feature for my Java Spring Boot + React ToDo app. At first, I thought it would be a quick and easy task—but it turned out to be more complex and insightful than expected. Behind a simple idea like “email verification” lies a good amount of planning, coding, and debugging.
✅ Project Goals for Email Verification:
-
Send a verification email after a user signs up.
-
Prevent login access until the user has verified their email.
-
Track email verification status in the backend securely.
-
Expire the verification token after a certain time (default: 24 hours).
π¨ What I’ve Done So Far:
✅ Backend (Spring Boot)
-
Configured SMTP settings in
application.properties
to send emails. -
Updated
pom.xml
to include necessary dependencies (Java Mail Sender, etc.). -
Created
AppConstants.java
in the config folder to define token expiration (e.g., 2 minutes for testing). -
Modified
AuthController.java
to:-
Enhance the signup and login logic
-
Add a new
/verify
endpoint to process verification links
-
-
Extended the
User
entity to include anemailVerified
boolean field. -
Created
VerificationToken.java
in the model layer to represent token info. -
Created
VerificationTokenRepository.java
and updatedUserRepository.java
. -
Implemented
EmailService.java
for sending out emails. -
Updated
UserService.java
to manage token generation, expiration, and verification flow.
✅ Frontend (React)
-
Modified
signup.js
to include email input and send it to the backend. -
Enhanced
login.js
to block users who haven’t verified their email yet. -
Planned:
-
A dedicated
/verify
page that will be opened from the email link and call the backend to confirm the token. -
A resend verification button in case the user missed or the token expired.
-
Even though those last two tasks weren’t initially requested, I realized they’re essential for a smoother user experience—so I plan to include them as part of this upgrade.
π‘ Key Takeaways
This task may sound simple in theory, but in practice, it required modifying almost every core layer of the app—model, controller, service, config, repository, and even the build files. It was a full-stack challenge that deepened my understanding of secure user registration.
No comments:
Post a Comment