The email verification system for student registration is now active and working.
Student signs up → Account created (verified=false) → Verification email sent → Student clicks link → Account verified → Can login
On Signup:
- Student enters: firstName, lastName, email (@guc.edu.eg), password, student ID, role
- Server creates user with
verified: false - Server generates a JWT token (valid for 24 hours)
- Server sends email with verification link to student's email
- Server also stores the email in the database (UserEmail model)
Verification Email Contains:
- Verification link:
http://localhost:5001/api/auth/verify?token=<JWT> - When clicked, this link:
- Validates the token
- Sets user.verified = true
- Redirects to:
http://localhost:3000/login?verified=1 - Login page shows success message
On Login Attempt:
- If user is NOT verified → Login fails with: "Account not verified. Check your email."
- If user IS verified → Login succeeds normally
-
Start the server and client:
# Terminal 1 - Server cd C:\Users\Khaled\VibeCoderz\server npm run dev # Terminal 2 - Client cd C:\Users\Khaled\VibeCoderz\client npm run dev
-
Open browser:
http://localhost:3000/signup -
Register a new student with your real @guc.edu.eg email
-
Check your email inbox for verification email from mohamedkhaledvp@gmail.com
-
Click the verification link in the email
-
You'll be redirected to login page with success message
-
Login with your credentials - should work!
If you don't want to use real email, you can get the verification link from the database:
cd C:\Users\Khaled\VibeCoderz\server
node scripts/getLastEmail.js student@guc.edu.egThis will print the stored email including the verification URL. Copy the URL and paste it in your browser.
Current setup uses Gmail:
- EMAIL_USER: mohamedkhaledvp@gmail.com
- EMAIL_PASSWORD: (App password configured in .env)
- Service: Gmail SMTP
The system automatically uses these credentials to send emails.
Creates new user account and sends verification email.
Request:
{
"firstName": "Ahmed",
"lastName": "Hassan",
"email": "ahmed.hassan@guc.edu.eg",
"password": "secure123",
"id": "58-1234",
"role": "student"
}Response (Student):
{
"message": "student signed up successfully",
"token": "...",
"user": {
"email": "ahmed.hassan@guc.edu.eg",
"verified": false,
...
}
}Verifies user email and redirects to login.
What it does:
- Validates JWT token
- Finds user by ID from token
- Sets user.verified = true
- Redirects to:
http://localhost:3000/login?verified=1
Standard login - requires verified account for students.
Error if not verified:
{
"error": "Account not verified. Check your email."
}- ✅
server/controllers/authController.js- Added verification logic - ✅
server/routes/auth.js- Added GET /verify route - ✅
server/utils/emailService.js- Enabled SMTP email sending
- ✅
client/src/components/auth/SignupForm.jsx- Shows verification message - ✅
client/src/components/auth/LoginForm.jsx- Shows verified success message - ✅
client/src/services/authService.js- Uses relative /api paths
- ✅
server/scripts/getLastEmail.js- Helper to fetch stored emails - ✅
server/scripts/findUser.js- Helper to check user status
The email sent to students looks like this:
Subject: Verify your GUC Events account
Hello Ahmed,
Please verify your email by clicking the link below:
[Verify Email]
This link will expire in 24 hours. If the link does not work,
copy-paste this URL into your browser:
http://localhost:5001/api/auth/verify?token=eyJhbGc...
After verification you will be redirected to the login page.
# Server Port
PORT=5001
# Database
MONGODB_URI=mongodb+srv://...
# JWT Secret (for verification tokens)
JWT_SECRET=yourSuperSecretKey
# Email Configuration (Gmail)
EMAIL_USER=mohamedkhaledvp@gmail.com
EMAIL_PASSWORD=leos dcrd fzda yaww
# Optional: Override defaults
CLIENT_URL=http://localhost:3000
SERVER_BASE_URL=http://localhost:5001- ✅ Verification tokens expire in 24 hours
- ✅ Tokens are signed with JWT_SECRET
- ✅ Users cannot login until verified
- ✅ Emails stored in database for audit trail
- ✅ Password hashed with bcrypt
| Role | Auto-Verified | Requires Email Verification |
|---|---|---|
| Student | ❌ No | ✅ Yes |
| Staff | ❌ No | |
| TA | ❌ No | |
| Professor | ❌ No | |
| Events Office | ✅ Yes | ❌ No |
| Admin | ✅ Yes | ❌ No |
- Check spam/junk folder
- Verify EMAIL_USER and EMAIL_PASSWORD in .env
- Check server logs for email sending errors
- Use Method 2 to get verification link from database
- User hasn't clicked verification link yet
- Check if email was sent (check server logs)
- Use scripts/getLastEmail.js to get verification link manually
- Verification links expire after 24 hours
- User needs to request new verification email (feature can be added if needed)
Want to add more features? Here are some ideas:
- Resend Verification Email - Add endpoint to resend verification
- Custom Email Templates - Better HTML email design
- Email Notifications - Send emails for other events (password reset, etc.)
- Verification Page - Show nice HTML page before redirecting to login
Let me know if you want any of these!