@@ -13,20 +13,58 @@ import {
1313 Button ,
1414 Flex ,
1515 Group ,
16+ Loader ,
1617} from '@mantine/core' ;
17- import { useNavigate } from '@tanstack/react-router' ;
18+ import { useLocation , useNavigate } from '@tanstack/react-router' ;
19+ import { useAuth } from '@/app/providers/auth-context' ;
20+ import { authAdapter } from '@/shared/api/auth' ;
1821
1922export function SignInModal ( ) {
2023 const [ opened , { open, close } ] = useDisclosure ( false ) ;
2124 const navigate = useNavigate ( ) ;
25+ const location = useLocation ( ) ;
2226
27+ const { user, isLoading, setIsLoading } = useAuth ( ) ;
2328 const modalContentHeight = rem ( 550 ) ;
2429
25- const mockLogin = ( ) => {
26- close ( ) ;
27- navigate ( { to : '/dashboard' } ) ;
30+ const handleGoogleLogin = async ( ) => {
31+ try {
32+ setIsLoading ( true ) ;
33+ await authAdapter . loginWithGoogle ( ) ;
34+ close ( ) ;
35+ } catch ( err ) {
36+ console . error ( 'Google Login failed' , err ) ;
37+ }
2838 } ;
2939
40+ const handleLogout = async ( ) => {
41+ try {
42+ setIsLoading ( true ) ;
43+ navigate ( { to : '/' , replace : false } ) ;
44+ await authAdapter . logout ( ) ;
45+ } catch ( err ) {
46+ console . error ( 'Logout failed' , err ) ;
47+ }
48+ } ;
49+
50+ if ( user ) {
51+ if ( location . pathname === '/' ) {
52+ return (
53+ < Button
54+ variant = "filled"
55+ onClick = { ( ) => navigate ( { to : '/dashboard' , replace : false } ) }
56+ >
57+ { isLoading ? < Loader size = { 'xs' } /> : 'Go to Dashboard' }
58+ </ Button >
59+ ) ;
60+ }
61+ return (
62+ < Button variant = "outline" onClick = { ( ) => handleLogout ( ) } >
63+ Logout
64+ </ Button >
65+ ) ;
66+ }
67+
3068 return (
3169 < >
3270 < Modal
@@ -115,9 +153,10 @@ export function SignInModal() {
115153 mt = "xl"
116154 size = "md"
117155 radius = "md"
118- onClick = { ( ) => mockLogin ( ) }
156+ loading = { isLoading } // Show loading state if auth is initializing
157+ onClick = { handleGoogleLogin } // Call t
119158 >
120- Login
159+ Continue with Google { ' ' }
121160 </ Button >
122161
123162 < Text ta = "center" mt = "md" size = "sm" >
@@ -147,7 +186,7 @@ export function SignInModal() {
147186 </ Modal >
148187
149188 < Button variant = "default" onClick = { open } >
150- Sign In
189+ { isLoading ? < Loader size = { 'xs' } /> : ' Sign In' }
151190 </ Button >
152191 </ >
153192 ) ;
0 commit comments