Skip to content
Shell
3.4 KB
Raw Blame

Sign-In Modal Implementation Plan

Goal

Replace hard redirect to /sign-in with a modal overlay that keeps users on the page they're viewing. Background blurs/darkens, clicking outside dismisses.

Current State

  • Middleware does hard redirect to /sign-in for protected routes
  • Users feel "trapped" in the login flow
  • Loses context of where they were

Proposed Architecture

Approach: Client-Side Auth Gating

Instead of server-side redirect, let the page load and show a modal overlay if not authenticated.

Key insight: This mirrors the existing PurchaseGate pattern - which already shows a modal instead of redirecting when user hasn't purchased.

Components to Create

  1. /components/auth/SignInModal.tsx

    • Reuses sign-in form logic from /app/(auth)/sign-in/page.tsx
    • Modal overlay with blur backdrop (pattern from LeadMagnetFunnel.tsx)
    • Google OAuth + Magic Link + Password options
    • onClose prop to dismiss
    • onSuccess prop to refresh content after auth
  2. /components/auth/AuthGate.tsx

    • Wrapper component for protected content
    • Checks auth state client-side
    • If not authenticated: show SignInModal over blurred content
    • If authenticated: render children normally

Middleware Changes

Modify /middleware.ts to not redirect for course module pages - let client-side AuthGate handle protection.

Page Updates

Wrap protected module pages in AuthGate:

// /app/courses/claude-for-knowledge-workers/module-1/page.tsx
export default function Module1Page() {
  return (
    <AuthGate moduleName="Module 1">
      <PurchaseGate productId="claude-for-knowledge-workers">
        {/* Module content */}
      </PurchaseGate>
    </AuthGate>
  )
}

Implementation Steps

  1. Create SignInModal - Extract sign-in form, add modal wrapper with blur backdrop
  2. Create AuthGate - Wrapper that checks auth and shows modal or children
  3. Update middleware - Remove course module redirect logic
  4. Wrap protected pages - Add AuthGate to module-1 through module-5

Files to Modify

File Change
/components/auth/SignInModal.tsx CREATE
/components/auth/AuthGate.tsx CREATE
/middleware.ts MODIFY
/app/courses/claude-for-knowledge-workers/module-1/page.tsx MODIFY
/app/courses/claude-for-knowledge-workers/module-2/page.tsx MODIFY
/app/courses/claude-for-knowledge-workers/module-3/page.tsx MODIFY
/app/courses/claude-for-knowledge-workers/module-4/page.tsx MODIFY
/app/courses/claude-for-knowledge-workers/module-5/page.tsx MODIFY

UX Flow (After Implementation)

  1. User clicks on Module 1 link
  2. Page loads with content visible but blurred behind modal
  3. SignInModal appears centered with dark backdrop
  4. User can:
    • Sign in → modal closes, content reveals
    • Click outside → modal closes, navigate back to course landing (user choice)
    • ESC key → same as click outside

Design Details

Modal styling (from LeadMagnetFunnel pattern):

// Backdrop - click to dismiss and navigate back
<motion.div
  className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm"
  onClick={() => router.push('/courses/claude-for-knowledge-workers')}
>
  // Modal - prevent click bubbling
  <motion.div
    className="bg-[var(--bg-primary)] rounded-2xl shadow-2xl max-w-md w-full"
    onClick={e => e.stopPropagation()}
  >