Skip to content

Commit 5b68db5

Browse files
committed
logging
1 parent d5b0497 commit 5b68db5

File tree

3 files changed

+28
-23
lines changed

3 files changed

+28
-23
lines changed

src/config/firebase.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {initializeApp} from 'firebase/app';
22
import {getFirestore} from 'firebase/firestore';
3-
import {getAuth, GoogleAuthProvider} from 'firebase/auth';
3+
import {getAuth} from 'firebase/auth';
44

55
const firebaseConfig = {
66
apiKey: "AIzaSyDXnEjvqq8lspDRlEJiDkztxWTmLYMoDGg",
@@ -15,6 +15,5 @@ const firebaseConfig = {
1515
const app = initializeApp(firebaseConfig);
1616
export const db = getFirestore(app);
1717
export const auth = getAuth(app);
18-
export const googleProvider = new GoogleAuthProvider();
1918

2019
export default app;

src/contexts/AuthContext.tsx

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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}`);

src/pages/Auth/Auth.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,14 @@ const Auth: React.FC = () => {
7070

7171
const handleAppleAuth = async () => {
7272
try {
73+
console.log('Apple button clicked, calling loginWithApple...');
7374
await loginWithApple();
75+
console.log('loginWithApple completed successfully');
7476
// Redirect to account page after successful login
7577
window.location.hash = 'account';
7678
} catch (error) {
77-
console.error('Apple sign-in failed:', error);
79+
console.error('Apple sign-in failed in handleAppleAuth:', error);
80+
alert(error instanceof Error ? error.message : 'Apple sign-in failed. Please try again.');
7881
}
7982
};
8083

@@ -119,7 +122,8 @@ const Auth: React.FC = () => {
119122
>
120123
<div className="apple-auth-content">
121124
<svg className="apple-icon" viewBox="0 0 24 24" width="18" height="18">
122-
<path fill="#000" d="M12.152 6.896c-.948 0-2.415-1.078-3.96-1.04-2.04.027-3.91 1.183-4.961 3.014-2.117 3.675-.546 9.103 1.519 12.09 1.013 1.454 2.208 3.09 3.792 3.039 1.52-.065 2.09-.987 3.935-.987 1.831 0 2.35.987 3.96.948 1.637-.026 2.676-1.48 3.676-2.948 1.156-1.688 1.636-3.325 1.662-3.415-.039-.013-3.182-1.221-3.22-4.857-.026-3.04 2.48-4.494 2.597-4.559-1.429-2.09-3.623-2.324-4.39-2.376-2-.156-3.675 1.09-4.61 1.09zM15.53 3.83c.843-1.012 1.4-2.427 1.245-3.83-1.207.052-2.662.805-3.532 1.818-.78.896-1.454 2.338-1.273 3.714 1.338.104 2.715-.688 3.559-1.701"/>
125+
<path fill="#000"
126+
d="M12.152 6.896c-.948 0-2.415-1.078-3.96-1.04-2.04.027-3.91 1.183-4.961 3.014-2.117 3.675-.546 9.103 1.519 12.09 1.013 1.454 2.208 3.09 3.792 3.039 1.52-.065 2.09-.987 3.935-.987 1.831 0 2.35.987 3.96.948 1.637-.026 2.676-1.48 3.676-2.948 1.156-1.688 1.636-3.325 1.662-3.415-.039-.013-3.182-1.221-3.22-4.857-.026-3.04 2.48-4.494 2.597-4.559-1.429-2.09-3.623-2.324-4.39-2.376-2-.156-3.675 1.09-4.61 1.09zM15.53 3.83c.843-1.012 1.4-2.427 1.245-3.83-1.207.052-2.662.805-3.532 1.818-.78.896-1.454 2.338-1.273 3.714 1.338.104 2.715-.688 3.559-1.701"/>
123127
</svg>
124128
<span>Continue with Apple</span>
125129
</div>

0 commit comments

Comments
 (0)