@@ -27,6 +27,7 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({children}) => {
2727 // Listen to Firebase auth state changes
2828 const unsubscribe = onAuthStateChanged ( auth , async ( firebaseUser ) => {
2929 if ( firebaseUser ) {
30+ console . log ( 'Auth state changed - user signed in:' , firebaseUser . uid ) ;
3031 // User is signed in, fetch their profile data
3132 try {
3233 const userData = await getUserFromFirestore ( firebaseUser . uid ) ;
@@ -43,6 +44,7 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({children}) => {
4344 setUser ( null ) ;
4445 }
4546 } else {
47+ console . log ( 'Auth state changed - user signed out' ) ;
4648 // User is signed out
4749 setUser ( null ) ;
4850 }
@@ -137,42 +139,42 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({children}) => {
137139 appleProvider . addScope ( 'name' ) ;
138140 appleProvider . addScope ( 'email' ) ;
139141
140- // Sign in with popup
142+ console . log ( 'Apple provider configured, attempting popup sign-in...' ) ;
143+
144+ // Try popup sign-in with detailed error handling
141145 const result = await signInWithPopup ( auth , appleProvider ) ;
142146
143- // The signed-in user info
144- const user = result . user ;
145- console . log ( 'Apple login successful for user:' , user . uid ) ;
147+ console . log ( 'Apple sign-in successful:' , result . user . uid ) ;
146148
147- // Apple credential
149+ // Extract credential details
148150 const credential = OAuthProvider . credentialFromResult ( result ) ;
149- const accessToken = credential ?. accessToken ;
150- const idToken = credential ?. idToken ;
151-
152- console . log ( 'Apple login credentials obtained' ) ;
153- // Note: onAuthStateChanged will handle user data fetching and setting
151+ if ( credential ) {
152+ console . log ( 'Apple credentials obtained' ) ;
153+ console . log ( 'Access token available:' , ! ! credential . accessToken ) ;
154+ console . log ( 'ID token available:' , ! ! credential . idToken ) ;
155+ }
154156
155157 } catch ( error : any ) {
156158 console . error ( 'Failed to process Apple login:' , error ) ;
157159
158- // Handle Errors here
160+ // Detailed error logging
161+ console . log ( 'Error code:' , error ?. code ) ;
162+ console . log ( 'Error message:' , error ?. message ) ;
163+ console . log ( 'Error customData:' , error ?. customData ) ;
164+ console . log ( 'Full error object:' , error ) ;
165+
166+ // Handle specific errors
159167 const errorCode = error . code ;
160168 const errorMessage = error . message ;
161169
162- // The email of the user's account used
163- const email = error . customData ?. email ;
164-
165- // The credential that was used
166- const credential = OAuthProvider . credentialFromError ( error ) ;
167-
168- console . log ( 'Apple login error details:' , { errorCode, errorMessage, email } ) ;
169-
170170 if ( errorCode === 'auth/operation-not-allowed' ) {
171171 throw new Error ( 'Apple Sign-In is not enabled. Please configure it in Firebase Console.' ) ;
172172 } else if ( errorCode === 'auth/popup-closed-by-user' ) {
173173 throw new Error ( 'Sign-in was cancelled by user.' ) ;
174174 } else if ( errorCode === 'auth/popup-blocked' ) {
175175 throw new Error ( 'Popup was blocked by browser. Please allow popups and try again.' ) ;
176+ } else if ( errorCode === 'auth/invalid-credential' ) {
177+ throw new Error ( 'Apple Sign-In configuration error. Please check your Firebase and Apple Developer Console settings.' ) ;
176178 }
177179
178180 throw new Error ( `Apple sign-in failed: ${ errorMessage } ` ) ;
0 commit comments