@@ -7,31 +7,30 @@ import Privacy from './pages/Privacy';
77import LearnMore from './pages/LearnMore' ;
88import Pricing from './pages/Pricing' ;
99import CliAuth from './pages/CliAuth/CliAuth' ;
10+ import { AuthProvider , useAuth } from './contexts/AuthContext' ;
1011
1112const AppContent : React . FC = ( ) => {
1213 const [ currentPage , setCurrentPage ] = useState ( 'welcome' ) ;
14+ const { user, isLoading} = useAuth ( ) ;
1315
1416 useEffect ( ( ) => {
1517 const handleHashChange = ( ) => {
1618 const hash = window . location . hash . slice ( 1 ) ;
17- // Extract the page name before any query parameters
18- const pageName = hash . split ( '?' ) [ 0 ] ;
19-
20- if ( pageName === 'auth' ) {
19+ if ( hash === 'auth' ) {
2120 setCurrentPage ( 'auth' ) ;
22- } else if ( pageName === 'account' ) {
21+ } else if ( hash === 'account' ) {
2322 setCurrentPage ( 'account' ) ;
24- } else if ( pageName === 'terms' ) {
23+ } else if ( hash === 'terms' ) {
2524 setCurrentPage ( 'terms' ) ;
26- } else if ( pageName === 'privacy' ) {
25+ } else if ( hash === 'privacy' ) {
2726 setCurrentPage ( 'privacy' ) ;
28- } else if ( pageName === 'learn-more' ) {
27+ } else if ( hash === 'learn-more' ) {
2928 setCurrentPage ( 'learn-more' ) ;
30- } else if ( pageName === 'pricing' ) {
29+ } else if ( hash === 'pricing' ) {
3130 setCurrentPage ( 'pricing' ) ;
32- } else if ( pageName === 'cli-auth' ) {
31+ } else if ( hash === 'cli-auth' ) {
3332 setCurrentPage ( 'cli-auth' ) ;
34- } else if ( pageName === 'welcome' ) {
33+ } else if ( hash === 'welcome' ) {
3534 setCurrentPage ( 'welcome' ) ;
3635 } else {
3736 setCurrentPage ( 'welcome' ) ;
@@ -46,6 +45,85 @@ const AppContent: React.FC = () => {
4645 } ;
4746 } , [ ] ) ;
4847
48+ // Show loading while checking auth state
49+ if ( isLoading ) {
50+ return (
51+ < div style = { {
52+ minHeight : '100vh' ,
53+ display : 'flex' ,
54+ alignItems : 'center' ,
55+ justifyContent : 'center' ,
56+ backgroundColor : '#111827' ,
57+ padding : '20px' ,
58+ fontFamily : '"Fira Code", "JetBrains Mono", "Monaco", "Menlo", "Ubuntu Mono", "Consolas", "source-code-pro", monospace'
59+ } } >
60+ < div style = { {
61+ background : '#1f2937' ,
62+ border : '1px solid #374151' ,
63+ borderRadius : '16px' ,
64+ boxShadow : '0 20px 40px rgba(0, 0, 0, 0.3)' ,
65+ padding : '48px 40px' ,
66+ textAlign : 'center' ,
67+ maxWidth : '400px' ,
68+ width : '100%'
69+ } } >
70+ < div style = { {
71+ width : '48px' ,
72+ height : '48px' ,
73+ margin : '0 auto 24px' ,
74+ background : '#ff6b35' ,
75+ borderRadius : '8px' ,
76+ display : 'flex' ,
77+ alignItems : 'center' ,
78+ justifyContent : 'center' ,
79+ fontSize : '24px' ,
80+ color : 'white' ,
81+ fontWeight : 'bold'
82+ } } >
83+ S
84+ </ div >
85+ < h1 style = { {
86+ fontSize : '24px' ,
87+ fontWeight : '600' ,
88+ color : '#f9fafb' ,
89+ margin : '0 0 8px 0'
90+ } } >
91+ Salamander
92+ </ h1 >
93+ < p style = { {
94+ fontSize : '14px' ,
95+ color : '#d1d5db' ,
96+ margin : '0 0 32px 0' ,
97+ fontWeight : '500'
98+ } } >
99+ Never be AFK
100+ </ p >
101+ < div style = { {
102+ width : '32px' ,
103+ height : '32px' ,
104+ border : '3px solid #374151' ,
105+ borderTop : '3px solid #ff6b35' ,
106+ borderRadius : '50%' ,
107+ animation : 'spin 1s linear infinite' ,
108+ margin : '0 auto'
109+ } } > </ div >
110+ </ div >
111+ </ div >
112+ ) ;
113+ }
114+
115+ // If user is logged in and trying to access auth page, redirect to account
116+ if ( user && currentPage === 'auth' ) {
117+ window . location . hash = 'account' ;
118+ return null ;
119+ }
120+
121+ // If user is not logged in and trying to access account page, redirect to welcome
122+ if ( ! user && currentPage === 'account' ) {
123+ window . location . hash = 'welcome' ;
124+ return null ;
125+ }
126+
49127 if ( currentPage === 'auth' ) {
50128 return < Auth /> ;
51129 }
@@ -79,7 +157,15 @@ const AppContent: React.FC = () => {
79157
80158const App : React . FC = ( ) => {
81159 return (
82- < AppContent />
160+ < AuthProvider >
161+ < AppContent />
162+ < style > { `
163+ @keyframes spin {
164+ 0% { transform: rotate(0deg); }
165+ 100% { transform: rotate(360deg); }
166+ }
167+ ` } </ style >
168+ </ AuthProvider >
83169 ) ;
84170} ;
85171
0 commit comments