Skip to content

Commit d5b0497

Browse files
committed
according to docs
1 parent 84bf706 commit d5b0497

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

src/contexts/AuthContext.tsx

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,44 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({children}) => {
138138
appleProvider.addScope('email');
139139

140140
// Sign in with popup
141-
await signInWithPopup(auth, appleProvider);
141+
const result = await signInWithPopup(auth, appleProvider);
142+
143+
// The signed-in user info
144+
const user = result.user;
145+
console.log('Apple login successful for user:', user.uid);
146+
147+
// Apple credential
148+
const credential = OAuthProvider.credentialFromResult(result);
149+
const accessToken = credential?.accessToken;
150+
const idToken = credential?.idToken;
151+
152+
console.log('Apple login credentials obtained');
142153
// Note: onAuthStateChanged will handle user data fetching and setting
143154

144155
} catch (error: any) {
145156
console.error('Failed to process Apple login:', error);
146-
if (error.code === 'auth/operation-not-allowed') {
157+
158+
// Handle Errors here
159+
const errorCode = error.code;
160+
const errorMessage = error.message;
161+
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+
170+
if (errorCode === 'auth/operation-not-allowed') {
147171
throw new Error('Apple Sign-In is not enabled. Please configure it in Firebase Console.');
172+
} else if (errorCode === 'auth/popup-closed-by-user') {
173+
throw new Error('Sign-in was cancelled by user.');
174+
} else if (errorCode === 'auth/popup-blocked') {
175+
throw new Error('Popup was blocked by browser. Please allow popups and try again.');
148176
}
149-
throw new Error('Apple sign-in failed. Please try again.');
177+
178+
throw new Error(`Apple sign-in failed: ${errorMessage}`);
150179
}
151180
};
152181

0 commit comments

Comments
 (0)