diff --git a/client/src/App.tsx b/client/src/App.tsx index 8905ade..7a7eef1 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -1,7 +1,7 @@ // client/src/App.tsx import React, { useEffect, useState } from "react"; -import { Switch, Route } from "wouter"; +import { Redirect, Switch, Route } from "wouter"; // Added Redirect import { TooltipProvider } from "@/components/ui/tooltip"; import { ThemeProvider } from "@/contexts/ThemeContext"; import { CodeThemeProvider } from "@/contexts/CodeThemeContext"; @@ -29,6 +29,7 @@ function AuthenticatedRouter() { + {/* Added for authenticated users */} ); @@ -38,6 +39,7 @@ function PublicRouter() { return ( + {/* Added for unauthenticated users */} {/* For non-matched routes, redirect to PublicHome */} @@ -45,6 +47,39 @@ function PublicRouter() { ); } +// SignInTriggerPage Helper Component +const SignInTriggerPage: React.FC = () => { + const { signIn, user, loading } = useAuthContext(); // useAuthContext is already imported + useEffect(() => { + // Only attempt to sign in if not already authenticated and not loading + if (!user && !loading) { + signIn(); + } + }, [signIn, user, loading]); + + // If already logged in (e.g., due to fast auth resolution), redirect to home. + if (user) { + return ; + } + // If still loading auth state + if (loading) { + return ( +
+
Loading authentication...
+
+
+ ); + } + // Default state while sign-in is being triggered or if user backs out of Google prompt + return ( +
+

Redirecting to sign-in...

+ {/* Or redirect to PublicHome if sign-in is not immediate / user needs to click again */} + {/* For now, this message is fine as signIn() should overlay Google prompt */} +
+ ); +}; + // Added debug component to show authentication state function AuthDebug({ user, loading }: { user: any, loading: boolean }) { return ( @@ -135,4 +170,4 @@ export default function App() { ); -} +} \ No newline at end of file diff --git a/client/src/pages/PublicHome.tsx b/client/src/pages/PublicHome.tsx index 658b5c9..f68aaac 100644 --- a/client/src/pages/PublicHome.tsx +++ b/client/src/pages/PublicHome.tsx @@ -1,6 +1,7 @@ // client/src/pages/PublicHome.tsx import React, { useState, useEffect, useMemo } from 'react'; -import { Link } from 'wouter'; // Or your routing library +import { Link } from 'wouter'; +import { useAuthContext } from '@/contexts/AuthContext'; // Added import SnippetGrid from '@/components/SnippetGrid'; // Adjust path as needed import { Input } from '@/components/ui/input'; // Adjust path for your UI components import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; // Adjust path @@ -11,6 +12,7 @@ import Layout from '@/components/Layout'; // Adjust path for Layout component const ALL_ITEMS_VALUE = "_ALL_"; // Define placeholder for "All" options const PublicHome: React.FC = () => { + const { signIn } = useAuthContext(); // Added const [snippets, setSnippets] = useState([]); const [allSnippets, setAllSnippets] = useState([]); // Store all fetched snippets for client-side filtering const [isLoading, setIsLoading] = useState(true); @@ -119,11 +121,13 @@ const PublicHome: React.FC = () => {

Discover & Share Code Snippets with the World.

- {/* Adjust if your login route is different */} - - +
@@ -208,4 +212,4 @@ const PublicHome: React.FC = () => { ); }; -export default PublicHome; +export default PublicHome; \ No newline at end of file