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.propertiesto send emails. -
Updated
pom.xmlto include necessary dependencies (Java Mail Sender, etc.). -
Created
AppConstants.javain the config folder to define token expiration (e.g., 2 minutes for testing). -
Modified
AuthController.javato:-
Enhance the signup and login logic
-
Add a new
/verifyendpoint to process verification links
-
-
Extended the
Userentity to include anemailVerifiedboolean field. -
Created
VerificationToken.javain the model layer to represent token info. -
Created
VerificationTokenRepository.javaand updatedUserRepository.java. -
Implemented
EmailService.javafor sending out emails. -
Updated
UserService.javato manage token generation, expiration, and verification flow.
✅ Frontend (React)
-
Modified
signup.jsto include email input and send it to the backend. -
Enhanced
login.jsto block users who haven’t verified their email yet. -
Planned:
-
A dedicated
/verifypage 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