This guide explains how the email verification system works in Campus Bridge and how to make it fully functional.
The Campus Bridge application implements a two-stage email authentication flow:
- User registers with name, email, and password
- System creates user account with
is_verified = 0 - System sends verification email with unique link
- User clicks verification link
- System updates user account to
is_verified = 1
- User logs in successfully
- System sends confirmation email to user's registered email
I've enhanced all email functions to consistently check for placeholder values:
- sendEmailConfirmation - Sent after successful login
- sendEmailVerification - Sent after user registration
- sendPasswordResetEmail - Sent when user requests password reset
All functions now:
- Check if email configuration exists
- Check if using placeholder values
- Skip sending if configuration is incomplete
Update your .env file with actual Gmail credentials:
EMAIL_SERVICE=gmail
EMAIL_USER=your-actual-gmail-address@gmail.com
EMAIL_PASS=your-16-character-app-password
EMAIL_FROM=your-actual-gmail-address@gmail.com-
Enable 2-Factor Authentication
- Go to your Google Account settings
- Click on "Security" in the left sidebar
- Under "Signing in to Google," click on "2-Step Verification"
- Follow the prompts to set up 2FA
-
Generate an App Password
- In the same "Security" section, scroll down to "App passwords"
- If you can't see this option, make sure 2FA is enabled
- Click on "App passwords"
- Select "Mail" as the app
- Select "Other (Custom name)" and type "Campus Bridge"
- Click "Generate"
- Copy the 16-character password (without spaces)
Replace the placeholder values with your actual information:
EMAIL_SERVICE=gmail
EMAIL_USER=john.doe@gmail.com
EMAIL_PASS=abcd1234efgh5678
EMAIL_FROM=john.doe@gmail.comAfter updating the .env file:
- Stop your server (Ctrl+C)
- Start your server again:
or
npm start
node server.js
- User fills registration form and submits
- System creates account with
is_verified = 0 - System sends verification email automatically
- User receives email with verification link
- User clicks link, which updates their account to
is_verified = 1
- User enters credentials and logs in
- System checks if user is verified (
is_verified = 1) - If verified, login proceeds and confirmation email is sent
- If not verified, login is denied with verification message
If email configuration is incomplete:
- Users see appropriate messages about verification
- System still enforces verification requirement
- Admin can manually verify users in database if needed
If you need to manually verify a user during testing:
UPDATE users SET is_verified = 1 WHERE email = 'user@example.com';- Never commit your .env file to version control
- Use App Passwords instead of regular passwords for better security
- Store your .env file securely
If emails are not being sent:
- Check that all environment variables are correctly set
- Verify that your email credentials are correct
- Ensure that your email provider allows SMTP access
- Check the server console for error messages
- Register a new user account
- Check that verification email is sent
- Click verification link in email
- Try to log in with verified account
- Check that login confirmation email is sent