grim commited on
Commit
94c3bbb
·
1 Parent(s): 3fc173e

fix: restore authenticated sign-in flow

Browse files
.github/copilot-instructions.md CHANGED
@@ -24,7 +24,8 @@ GetCert is an end-to-end certification SaaS platform that verifies practical dev
24
  7. **Local Development (`npm run dev:full`, `local-api.ts`)**: The development workflow mounts Vercel handlers through a local Express API wrapper on port 3001 using `tsx watch` for hot-reloading. If a healthy API is already listening on port 3001, the wrapper should retry health checks and reuse it instead of failing with `EADDRINUSE`. The wrapper should pass handlers a plain Vercel-shaped request object with merged path params and query string data instead of mutating Express's `IncomingMessage`.
25
  8. **StrictMode-Safe Course Start Guards (`src/components/certification-flow/CertificationFlowManager.tsx`)**: Development remounts can replay course selection and resume effects. Guard start/resume flows with module-level in-flight promise deduplication and idempotency checks so React StrictMode does not double-start a certification flow or leave the UI stuck on the loader.
26
  9. **Authenticated Shell Stability (`src/App.tsx`)**: Keep the authenticated router tree defined at module scope so re-renders do not remount the full dashboard/certification shell. Resume URLs should be cleared through React Router navigation, not raw `window.history` calls, so `useSearchParams()` stays in sync and resume effects do not replay on the same navigation entry.
27
- 10. **Layered Video Retrieval (`api/v2/services/videoSearch.ts`, `api/v2/services/youtubeResourceService.ts`)**: Course video selection now uses a layered pipeline with official YouTube Data API search, scraper fallback, a local skill-aware catalog, and deterministic offline fallbacks. Keep retrieval separate from validation, apply strict stage budgets, cache successful selections in memory, and refresh stale skill indexes in the background instead of blocking course generation on live scraping alone.
 
28
 
29
  ## Coding Standards & Conventions
30
  - **TypeScript First:** Ensure strict typing for new features. Use interfaces for all Supabase API responses.
 
24
  7. **Local Development (`npm run dev:full`, `local-api.ts`)**: The development workflow mounts Vercel handlers through a local Express API wrapper on port 3001 using `tsx watch` for hot-reloading. If a healthy API is already listening on port 3001, the wrapper should retry health checks and reuse it instead of failing with `EADDRINUSE`. The wrapper should pass handlers a plain Vercel-shaped request object with merged path params and query string data instead of mutating Express's `IncomingMessage`.
25
  8. **StrictMode-Safe Course Start Guards (`src/components/certification-flow/CertificationFlowManager.tsx`)**: Development remounts can replay course selection and resume effects. Guard start/resume flows with module-level in-flight promise deduplication and idempotency checks so React StrictMode does not double-start a certification flow or leave the UI stuck on the loader.
26
  9. **Authenticated Shell Stability (`src/App.tsx`)**: Keep the authenticated router tree defined at module scope so re-renders do not remount the full dashboard/certification shell. Resume URLs should be cleared through React Router navigation, not raw `window.history` calls, so `useSearchParams()` stays in sync and resume effects do not replay on the same navigation entry.
27
+ 10. **Supabase Email Callback Completion (`src/App.tsx`, `src/hooks/useAuth.ts`)**: Email confirmation links must complete the Supabase code exchange on the `/auth/callback` route before session checks. Password sign-in should eagerly hydrate local auth state from the returned session so the dashboard can render immediately even before the listener finishes syncing.
28
+ 11. **Layered Video Retrieval (`api/v2/services/videoSearch.ts`, `api/v2/services/youtubeResourceService.ts`)**: Course video selection now uses a layered pipeline with official YouTube Data API search, scraper fallback, a local skill-aware catalog, and deterministic offline fallbacks. Keep retrieval separate from validation, apply strict stage budgets, cache successful selections in memory, and refresh stale skill indexes in the background instead of blocking course generation on live scraping alone.
29
 
30
  ## Coding Standards & Conventions
31
  - **TypeScript First:** Ensure strict typing for new features. Use interfaces for all Supabase API responses.
src/App.tsx CHANGED
@@ -62,7 +62,10 @@ function AuthCallback() {
62
  useEffect(() => {
63
  const handleAuthCallback = async () => {
64
  try {
65
- const { data, error } = await supabase.auth.getSession();
 
 
 
66
 
67
  if (error) {
68
  logger.error('Auth callback error:', error);
@@ -284,6 +287,14 @@ function App() {
284
  );
285
  }
286
 
 
 
 
 
 
 
 
 
287
  // Show homepage for new users
288
  if (showHomepage && !authState.emailConfirmationSent) {
289
  // Debug homepage visibility
@@ -390,11 +401,7 @@ function App() {
390
  </Router>
391
  );
392
  }
393
- return (
394
- <Router future={routerFuture}>
395
- <AuthenticatedAppRoutes user={user!} onSignOut={handleSignOut} />
396
- </Router>
397
- );
398
  }
399
 
400
  export default function WrappedApp() {
 
62
  useEffect(() => {
63
  const handleAuthCallback = async () => {
64
  try {
65
+ const code = new URLSearchParams(window.location.search).get('code');
66
+ const { data, error } = code
67
+ ? await supabase.auth.exchangeCodeForSession(code)
68
+ : await supabase.auth.getSession();
69
 
70
  if (error) {
71
  logger.error('Auth callback error:', error);
 
287
  );
288
  }
289
 
290
+ if (user) {
291
+ return (
292
+ <Router future={routerFuture}>
293
+ <AuthenticatedAppRoutes user={user} onSignOut={handleSignOut} />
294
+ </Router>
295
+ );
296
+ }
297
+
298
  // Show homepage for new users
299
  if (showHomepage && !authState.emailConfirmationSent) {
300
  // Debug homepage visibility
 
401
  </Router>
402
  );
403
  }
404
+ return null;
 
 
 
 
405
  }
406
 
407
  export default function WrappedApp() {
src/hooks/useAuth.ts CHANGED
@@ -125,6 +125,15 @@ export function useAuth() {
125
  setAuthState(prev => ({ ...prev, loading: false }));
126
  throw error;
127
  }
 
 
 
 
 
 
 
 
 
128
  return data;
129
  } catch (error) {
130
  setAuthState(prev => ({ ...prev, loading: false }));
 
125
  setAuthState(prev => ({ ...prev, loading: false }));
126
  throw error;
127
  }
128
+
129
+ setAuthState(prev => ({
130
+ ...prev,
131
+ user: data.session?.user ?? prev.user,
132
+ emailConfirmationSent: false,
133
+ pendingEmail: null,
134
+ loading: false,
135
+ }));
136
+
137
  return data;
138
  } catch (error) {
139
  setAuthState(prev => ({ ...prev, loading: false }));