The application now uses email verification codes for secure authentication. Users must verify ownership of their email address to sign in.
- Email: arsalan.anwer9050@gmail.com
- Role: admin
- Redirect: / (Admin Dashboard)
- Email: arsalan.anwer9050@yahoo.com
- Role: student
- Redirect: /dashboard (Student Dashboard)
- User enters email address
- System checks if email exists in database
- System checks rate limiting (90 seconds between requests)
- System generates 6-digit code
- Code is saved to database with 10-minute expiration
- Email is sent with verification code
- User enters 6-digit code
- System validates code against database
- System checks if code has expired
- If valid, user is signed in and redirected based on role
- Used codes are deleted immediately
- Users can request a new code every 90 seconds
- UI shows countdown timer before "Resend" button appears
- API returns helpful error messages with wait time
- Codes expire after 10 minutes
- Expired codes are automatically deleted from database
- MongoDB TTL index ensures cleanup
- Only registered users (in database) can receive codes
- Prevents spam and unauthorized access attempts
- Clear error message: "No account found with this email. Please contact your office manager."
- Clean, modern interface
- Email validation
- Clear call-to-action button
- Helper text explaining the process
- Large, monospace input for 6-digit code
- Auto-focus on code input
- Visual feedback for code entry
- Disabled submit until 6 digits entered
- "Change email" option to go back
- Resend code functionality with countdown
- Clear expiration notice (10 minutes)
- User-friendly error messages
- Visual error indicators (red alert boxes)
- Success messages (green alert boxes)
- Specific errors for:
- Email not found
- Rate limiting (with countdown)
- Invalid code
- Expired code
- Email sending failures
The system uses Gmail SMTP for sending verification codes:
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=arsalan.anwer9050@gmail.com
SMTP_PASS=[App Password]
SMTP_FROM="Schedule Builder <noreply@schedulebuilder.com>"
- Start dev server:
npm run dev - Visit: http://localhost:3000/login
- Enter test email (gmail for admin, yahoo for student)
- Check your email inbox
- Enter the 6-digit code
- Verify redirect to correct dashboard
- Enter valid email → Code sent
- Enter correct code → Signed in
- Redirected to appropriate dashboard
- Enter unregistered email
- Error: "No account found with this email. Please contact your office manager."
- Request code
- Immediately request another code
- Error with countdown: "Please wait [X] seconds before requesting a new code"
- Request code
- Wait 10+ minutes
- Enter code
- Error: "Verification code has expired. Please request a new one."
- Request code
- Enter wrong digits
- Error: "Invalid verification code"
- Request code
- Wait 90 seconds for countdown
- Click "Resend verification code"
- New code sent to email
{
email: String (unique, lowercase)
name: String
role: 'admin' | 'student'
createdAt: Date
updatedAt: Date
}{
email: String (lowercase)
code: String (6 digits)
expiresAt: Date
createdAt: Date (TTL index: 600 seconds)
}Request a verification code
Request:
{
"email": "arsalan.anwer9050@gmail.com"
}Success Response:
{
"success": true,
"message": "Verification code sent to your email"
}Error Responses:
- 400: Email required
- 404: Email not found
- 429: Rate limited
- 500: Email sending failed
Verify the code and sign in
Request:
{
"email": "arsalan.anwer9050@gmail.com",
"code": "123456"
}Success Response:
{
"success": true,
"message": "Login successful",
"redirectUrl": "/"
}Error Responses:
- 400: Email and code required
- 401: Invalid or expired code
- 404: User not found
- 500: Server error
- Consider using a professional email service (SendGrid, AWS SES, etc.)
- Set up SPF, DKIM, and DMARC records
- Monitor bounce rates and spam complaints
- Consider implementing CAPTCHA for rate limiting
- Add IP-based rate limiting
- Implement account lockout after too many failed attempts
- Add audit logging for authentication events
- Consider adding SMS as an alternative verification method
- Implement "Remember this device" functionality
- Add email templates with organization branding
- Consider shorter codes (4 digits) with more frequent rotation