11'use client' ;
22
3- import { useState } from 'react' ;
3+ import { useState , useEffect } from 'react' ;
44import { useRouter } from 'next/navigation' ;
55import { useNostrSigner } from '@/hooks/useNostrSigner' ;
66import { useAuthStore } from '@/stores/useAuthStore' ;
77import { logger } from '@/services/core/LoggingService' ;
88
99export default function SigninPage ( ) {
1010 const router = useRouter ( ) ;
11- const { isAvailable, isLoading, signer, detectSignerOnDemand , error } = useNostrSigner ( ) ;
11+ const { isAvailable, isLoading, signer, error } = useNostrSigner ( ) ;
1212 const { setUser, setAuthenticated } = useAuthStore ( ) ;
1313 const [ isSigningIn , setIsSigningIn ] = useState ( false ) ;
1414 const [ signinError , setSigninError ] = useState < string | null > ( null ) ;
15-
16- // Don't detect signer automatically - only when user clicks sign in
15+ const [ signerDetected , setSignerDetected ] = useState ( false ) ;
16+
17+ // Detect signer on page load to show status
18+ useEffect ( ( ) => {
19+ const checkSigner = ( ) => {
20+ const hasSigner = typeof window !== 'undefined' && ! ! window . nostr ;
21+ setSignerDetected ( hasSigner ) ;
22+ logger . info ( 'Signer check on page load' , { hasSigner } ) ;
23+ } ;
24+
25+ checkSigner ( ) ;
26+ } , [ ] ) ;
1727
1828 const handleSignIn = async ( ) => {
19- console . log ( 'Sign In button clicked - detecting signer...' ) ;
20-
21- // Detect signer when user clicks sign in
22- await detectSignerOnDemand ( ) ;
29+ console . log ( 'Sign In button clicked - invoking signer...' ) ;
2330
2431 if ( ! isAvailable || ! signer ) {
32+ logger . warn ( 'No signer available' , { isAvailable, hasSigner : ! ! signer } ) ;
2533 setSigninError ( 'No Nostr signer available. Please install a Nostr browser extension.' ) ;
2634 return ;
2735 }
2836
37+ logger . info ( 'Invoking signer for authentication...' ) ;
38+
2939 setIsSigningIn ( true ) ;
3040 setSigninError ( null ) ;
3141
@@ -111,7 +121,7 @@ export default function SigninPage() {
111121 </ p >
112122 </ div >
113123
114- { ! isAvailable && ! isLoading && (
124+ { ! signerDetected && ! isLoading && (
115125 < div className = "mb-6 p-4 bg-yellow-50 border border-yellow-200 rounded-lg" >
116126 < h3 className = "font-semibold text-yellow-800 mb-2" > Nostr Extension Required</ h3 >
117127 < p className = "text-yellow-700 text-sm mb-3" >
@@ -128,6 +138,20 @@ export default function SigninPage() {
128138 </ div >
129139 ) }
130140
141+ { signerDetected && (
142+ < div className = "mb-6 p-4 bg-green-50 border border-green-200 rounded-lg" >
143+ < div className = "flex items-center" >
144+ < svg className = "w-5 h-5 text-green-600 mr-2" fill = "none" stroke = "currentColor" viewBox = "0 0 24 24" >
145+ < path strokeLinecap = "round" strokeLinejoin = "round" strokeWidth = { 2 } d = "M5 13l4 4L19 7" />
146+ </ svg >
147+ < h3 className = "font-semibold text-green-800" > Signer Detected!</ h3 >
148+ </ div >
149+ < p className = "text-green-700 text-sm mt-1" >
150+ Your Nostr extension is ready. Click "Sign In with Nostr" to continue.
151+ </ p >
152+ </ div >
153+ ) }
154+
131155 { isLoading && (
132156 < div className = "text-center py-8" >
133157 < div className = "animate-spin rounded-full h-8 w-8 border-b-2 border-primary-600 mx-auto mb-4" > </ div >
0 commit comments