11// client/src/App.tsx
22
33import React , { useEffect , useState } from "react" ;
4- import { Switch , Route } from "wouter" ;
4+ import { Redirect , Switch , Route } from "wouter" ; // Added Redirect
55import { TooltipProvider } from "@/components/ui/tooltip" ;
66import { ThemeProvider } from "@/contexts/ThemeContext" ;
77import { CodeThemeProvider } from "@/contexts/CodeThemeContext" ;
@@ -29,6 +29,7 @@ function AuthenticatedRouter() {
2929 < Route path = "/tags" component = { Tags } />
3030 < Route path = "/settings" component = { Settings } />
3131 < Route path = "/shared/:shareId" component = { SharedSnippet } />
32+ < Route path = "/login" > < Redirect to = "/" /> </ Route > { /* Added for authenticated users */ }
3233 < Route component = { NotFound } />
3334 </ Switch >
3435 ) ;
@@ -38,13 +39,47 @@ function PublicRouter() {
3839 return (
3940 < Switch >
4041 < Route path = "/" component = { PublicHome } />
42+ < Route path = "/login" component = { SignInTriggerPage } /> { /* Added for unauthenticated users */ }
4143 < Route path = "/shared/:shareId" component = { SharedSnippet } />
4244 { /* For non-matched routes, redirect to PublicHome */ }
4345 < Route component = { PublicHome } />
4446 </ Switch >
4547 ) ;
4648}
4749
50+ // SignInTriggerPage Helper Component
51+ const SignInTriggerPage : React . FC = ( ) => {
52+ const { signIn, user, loading } = useAuthContext ( ) ; // useAuthContext is already imported
53+ useEffect ( ( ) => {
54+ // Only attempt to sign in if not already authenticated and not loading
55+ if ( ! user && ! loading ) {
56+ signIn ( ) ;
57+ }
58+ } , [ signIn , user , loading ] ) ;
59+
60+ // If already logged in (e.g., due to fast auth resolution), redirect to home.
61+ if ( user ) {
62+ return < Redirect to = "/" /> ;
63+ }
64+ // If still loading auth state
65+ if ( loading ) {
66+ return (
67+ < div className = "h-screen flex flex-col items-center justify-center" >
68+ < div className = "mb-4" > Loading authentication...</ div >
69+ < div className = "animate-spin h-8 w-8 border-t-2 border-b-2 border-blue-500 rounded-full" > </ div >
70+ </ div >
71+ ) ;
72+ }
73+ // Default state while sign-in is being triggered or if user backs out of Google prompt
74+ return (
75+ < div className = "h-screen flex flex-col items-center justify-center" >
76+ < p > Redirecting to sign-in...</ p >
77+ { /* Or redirect to PublicHome if sign-in is not immediate / user needs to click again */ }
78+ { /* For now, this message is fine as signIn() should overlay Google prompt */ }
79+ </ div >
80+ ) ;
81+ } ;
82+
4883// Added debug component to show authentication state
4984function AuthDebug ( { user, loading } : { user : any , loading : boolean } ) {
5085 return (
@@ -135,4 +170,4 @@ export default function App() {
135170 </ CodeThemeProvider >
136171 </ ThemeProvider >
137172 ) ;
138- }
173+ }
0 commit comments