Project: IndexNow Studio
Date: September 19, 2025
Status: Planning Phase
-
Dedicated
/verifypage atapp/(public)/auth/verify/page.tsx- Shows "Check your email" message with email parameter
- Redirects back to login page
- Proper styling matching project design
-
Registration Flow
app/(public)/auth/register/page.tsxredirects to/verify?email=user@email.comon success- Uses Supabase Auth for user registration
- Registration API endpoint at
/api/v1/auth/register
-
Auth Callback System
app/auth/callback/route.tshandles Supabase verification tokens- Exchanges code for session using
exchangeCodeForSession - Redirects to dashboard on successful verification
-
Authentication Context
lib/contexts/AuthContext.tsxmanages global auth state- Tracks
emailVerificationproperty based onemail_confirmed_at lib/auth/auth.tsincludes email verification status in user object
-
Email Confirmation Check During Login
- Current login flow (
app/login/page.tsx) doesn't checkemail_confirmed_atstatus - Unconfirmed users can access dashboard directly after login
- No redirect to
/verifyfor unconfirmed users
- Current login flow (
-
Proper Supabase Verification URL Handling
- Current callback route doesn't distinguish between different verification types
- Need to handle signup confirmation vs password reset vs magic link flows
- Missing proper error handling for expired/invalid tokens
-
Enhanced Verification Page Features
- No option to resend confirmation email
- No handling for different verification states (expired, invalid, etc.)
- No user feedback for verification process
Objective: Redirect unconfirmed users to /verify instead of dashboard
Implementation Details:
- Modify
app/login/page.tsxto check user's email confirmation status after login - If
user.emailVerification === falseoremail_confirmed_at === null, redirect to/verify?email=user@email.com - Add proper loading states and error handling
- Maintain current login functionality for confirmed users
Files to Modify:
app/login/page.tsx- Add email confirmation check after successful loginlib/auth/auth.ts- EnsureemailVerificationproperty is properly set
Objective: Properly handle different types of verification URLs from Supabase
Current Supabase Verification URL Format:
https://indexnow.studio/auth/v1/verify?token=e98ea7ff93b5a8f26694e9706571579f74e005df481e08ab09adecdf&type=signup&redirect_to=http://localhost:3000
Implementation Details:
- Modify
app/auth/callback/route.tsto handle differenttypeparameters:type=signup- Email confirmation for new registrationtype=recovery- Password reset verificationtype=magiclink- Magic link authentication
- Add proper success/error redirects based on verification type
- Update
email_confirmed_atstatus in database when verification succeeds - Add comprehensive error handling for expired/invalid tokens
Files to Modify:
app/auth/callback/route.ts- Enhanced callback handling- Create new route:
app/auth/v1/verify/route.ts- Handle Supabase verification URLs
Objective: Improve user experience during email verification process
Implementation Details:
- Add "Resend Email" functionality with rate limiting
- Show different messages based on verification state (pending, expired, invalid)
- Add countdown timer for resend functionality
- Improve error handling and user feedback
- Add automatic refresh/polling to check verification status
Features to Add:
- Resend confirmation email button (with 60-second cooldown)
- Real-time verification status checking
- Better error messages for common issues
- Progress indicators
- Success state handling
Files to Modify:
app/(public)/auth/verify/page.tsx- Enhanced verification page- Create API route:
app/api/v1/auth/resend-verification/route.ts
Objective: Improve authentication state management for email verification
Implementation Details:
- Enhance
useAuthhook to provide email verification status - Add method to refresh authentication state after verification
- Improve user object structure to include verification details
- Add helper methods for verification-related actions
Files to Modify:
lib/contexts/AuthContext.tsx- Add email verification helperslib/auth/auth.ts- Enhance user object with verification data
-
Update Login Page
// In app/login/page.tsx - after successful login const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setIsLoading(true) setError("") try { const { user } = await authService.signIn(email, password) // Check email verification status if (!user?.emailVerification) { router.push(`/verify?email=${encodeURIComponent(email)}`) return } router.push("/dashboard") } catch (error: any) { setError(error.message || "Login failed") } finally { setIsLoading(false) } }
-
Enhance Auth Service
- Ensure
getCurrentUser()properly setsemailVerificationfield - Add helper method
isEmailConfirmed()
- Ensure
-
Create Supabase Verification Route
// New file: app/auth/v1/verify/route.ts export async function GET(request: NextRequest) { const { searchParams, origin } = new URL(request.url) const token = searchParams.get('token') const type = searchParams.get('type') const redirectTo = searchParams.get('redirect_to') // Handle different verification types switch (type) { case 'signup': // Handle email confirmation break case 'recovery': // Handle password reset break // etc. } }
-
Update Existing Callback Route
- Maintain backward compatibility
- Add proper error handling
- Improve redirect logic
-
Add Resend Functionality
// In app/(public)/auth/verify/page.tsx const [canResend, setCanResend] = useState(false) const [countdown, setCountdown] = useState(60) const handleResendEmail = async () => { // Call resend API // Start countdown timer // Update UI state }
-
Create Resend API Route
// New file: app/api/v1/auth/resend-verification/route.ts export async function POST(request: NextRequest) { // Validate request // Check rate limiting // Resend verification email via Supabase // Return success/error response }
-
User Flow Testing
- Test registration → verification → login flow
- Test unconfirmed user login redirect
- Test resend functionality
- Test expired token handling
-
Error Handling
- Add comprehensive error messages
- Handle edge cases
- Improve user feedback
The project uses Supabase Auth's built-in auth.users table with the email_confirmed_at field:
-- Supabase auth.users table (managed by Supabase)
SELECT email_confirmed_at FROM auth.users WHERE id = 'user-id';Note: Since this project uses Supabase's managed auth system, no custom database changes are required. The email_confirmed_at field is automatically managed by Supabase Auth.
- Implement rate limiting for resend email functionality
- Prevent spam/abuse of verification system
- Use server-side validation
- Ensure proper token validation in callback routes
- Handle expired tokens gracefully
- Prevent token replay attacks
- Don't expose sensitive user data in URLs
- Use proper HTTPS redirects
- Sanitize email parameters
- Unconfirmed users are redirected to
/verifywhen trying to access dashboard - Email verification URLs from Supabase work correctly
- Users can resend verification emails with rate limiting
- Verification page shows proper status and feedback
- Email confirmation updates
email_confirmed_atin database
- Seamless flow from registration → verification → dashboard
- Clear error messages for common issues
- Professional UI matching project design system
- Mobile-responsive verification page
- Proper loading states throughout the flow
- No breaking changes to existing authentication flow
- Backward compatibility with existing URLs
- Proper error handling and logging
- SEO-friendly page structure
- Follow project coding standards and patterns
- Phase 1 (Core Login Enhancement): 2-3 hours
- Phase 2 (Verification URL Handling): 3-4 hours
- Phase 3 (Enhanced Verification Page): 2-3 hours
- Phase 4 (Testing & Polish): 1-2 hours
Total Estimated Time: 8-12 hours
- Breaking existing auth flow - Mitigate by thorough testing
- Supabase URL format changes - Handle gracefully with fallbacks
- User confusion during verification - Provide clear instructions
- Rate limiting bypass - Implement server-side validation
- Test all existing auth flows still work
- Test new verification flows thoroughly
- Test edge cases (expired tokens, invalid emails, etc.)
- Test mobile responsiveness
- Test with different email providers
- This plan maintains full compatibility with existing authentication system
- All changes follow project's Next.js + Supabase architecture
- UI/UX follows established project design system and color scheme
- Implementation will be done in phases to minimize risk