11"use client" ;
22
3- import { signOut , useSession } from "next-auth/react" ;
4- import {
5- SignInButton ,
6- SignOutButton ,
7- } from "../../../components/api-wallet/AuthButtons" ;
8- import { SignMethods } from "@/components/api-wallet/SignMethods" ;
9- import { useEffect , useState } from "react" ;
10- import { teeService } from "../../../lib/tee-service" ;
11- import { UserInfo } from "@/components/api-wallet/UserInfo" ;
3+ import { useEffect } from "react" ;
4+ import { useRouter } from "next/navigation" ;
5+ import { SignInButton } from "../../../components/api-wallet/AuthButtons" ;
126import { BackButton } from "@/components/BackButton" ;
13- import { MobileMenu } from "@/components/MobileMenu" ;
14- import { TeeDocsButton } from "@/components/TeeDocsButton" ;
7+ import { useApiWallet } from "@/contexts/ApiWalletContext" ;
158
169export default function Home ( ) {
17- const { status } = useSession ( ) ;
18- const [ publicAddress , setPublicAddress ] = useState < string | null > ( null ) ;
10+ const router = useRouter ( ) ;
11+ const { isAuthenticated , isLoading } = useApiWallet ( ) ;
1912
2013 useEffect ( ( ) => {
21- if ( ! publicAddress && status === "authenticated" ) {
22- teeService
23- . getOrCreateWallet ( )
24- . then ( ( address ) => {
25- setPublicAddress ( address ) ;
26- } )
27- . catch ( ( error ) => {
28- console . error ( "Failed to get or create wallet:" , error ) ;
29- // Only sign out if it's an auth-related error
30- if ( error . requiresReauth ) {
31- console . log ( "Auth error detected, signing out..." ) ;
32- signOut ( ) ;
33- }
34- } ) ;
14+ if ( isAuthenticated ) {
15+ router . push ( '/api-wallet/wallet' ) ;
3516 }
36- } , [ publicAddress , status ] ) ;
17+ } , [ isAuthenticated , router ] ) ;
3718
38- if ( status === "loading" ) {
19+ // Show loading state while checking authentication
20+ if ( isLoading ) {
3921 return (
40- < div className = "flex flex-col items-center justify-center min-h-[500px]" >
41- < div className = "text-2xl font-bold" > Loading...</ div >
22+ < div className = "relative min-h-screen flex items-center justify-center" >
23+ < div className = "text-center" >
24+ < div className = "animate-spin rounded-full h-12 w-12 border-b-2 border-primary mx-auto mb-4" > </ div >
25+ < p className = "text-muted-foreground" > Checking authentication...</ p >
26+ </ div >
4227 </ div >
4328 ) ;
4429 }
4530
31+ // Don't render the auth form if user is authenticated (redirect will happen)
32+ if ( isAuthenticated ) {
33+ return null ;
34+ }
35+
4636 return (
4737 < div className = "relative min-h-screen" >
48- < div className = "relative z-10 flex flex-col items-center min-h-screen p-8 pb-20 pt-16 sm:pt-20 gap-8 sm:gap-16 sm:p-20" >
49- { /* Mobile: Hamburger Menu */ }
50- < MobileMenu >
51- < div onClick = { ( ) => { } } >
52- < TeeDocsButton className = "w-full" />
53- </ div >
54- { status === "authenticated" && (
55- < div onClick = { ( ) => { } } >
56- < SignOutButton className = "h-12" />
57- </ div >
58- ) }
59- </ MobileMenu >
60-
61- { /* Desktop: Positioned buttons */ }
62- < div className = "hidden sm:block" >
63- < BackButton />
64- < TeeDocsButton />
65- </ div >
38+ < div className = "relative z-10 flex flex-col items-center min-h-screen p-8 pt-12 pb-20 gap-2 sm:gap-16 sm:p-20" >
39+ < BackButton className = "hidden sm:block" />
6640
6741 { /* Header */ }
6842 < div className = "flex flex-col items-center gap-6 text-center" >
69- < div className = "relative py-4" >
43+ < div className = "relative py-8 sm:py- 4" >
7044 < h1 className = "text-6xl font-bold gradient-text mb-4 leading-tight" >
7145 Magic API Wallets
7246 </ h1 >
@@ -75,27 +49,19 @@ export default function Home() {
7549 </ div >
7650
7751 { /* Main Content */ }
78- { status === "authenticated" && (
79- < div className = "flex flex-col items-center gap-12 w-full max-w-4xl" >
80- < UserInfo publicAddress = { publicAddress } />
81- < SignMethods publicAddress = { publicAddress } />
82- < div className = "hidden sm:block" >
83- < SignOutButton />
84- </ div >
52+ < div className = "flex flex-col items-center gap-8 w-full max-w-2xl" >
53+ < div className = "text-center" >
54+ < h2 className = "text-2xl font-semibold mb-4 text-foreground" >
55+ Get Started
56+ </ h2 >
57+ < p className = "text-muted-foreground mb-8" >
58+ Connect your account to access your secure TEE wallet
59+ </ p >
8560 </ div >
86- ) }
8761
88- { status === "unauthenticated" && (
89- < div className = "flex flex-col items-center gap-8" >
90- < div className = "text-center" >
91- < h2 className = "text-2xl font-semibold mb-4" > Get Started</ h2 >
92- < p className = "text-muted-foreground mb-8" >
93- Connect your account to access your secure TEE wallet
94- </ p >
95- </ div >
96- < SignInButton />
97- </ div >
98- ) }
62+ { /* Sign In Button */ }
63+ < SignInButton />
64+ </ div >
9965 </ div >
10066 </ div >
10167 ) ;
0 commit comments