Skip to content

Commit 961837d

Browse files
chore: debug production apple
1 parent 13a116c commit 961837d

File tree

1 file changed

+47
-9
lines changed

1 file changed

+47
-9
lines changed

lib/appwrite/auth.ts

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,26 @@ export class AuthService {
120120

121121
const redirectUrl = `${window.location.origin}/auth/callback`;
122122

123-
// Add debug logging if enabled
124-
if (process.env.NEXT_PUBLIC_DEBUG_AUTH === "true") {
125-
console.log("Apple OAuth - Redirect URL:", redirectUrl);
126-
console.log("Apple OAuth - Current origin:", window.location.origin);
123+
// Add debug info to sessionStorage for production debugging
124+
if (typeof window !== "undefined") {
125+
const debugInfo = {
126+
timestamp: new Date().toISOString(),
127+
action: "apple_oauth_start",
128+
redirectUrl,
129+
origin: window.location.origin,
130+
hostname: window.location.hostname,
131+
};
132+
133+
try {
134+
sessionStorage.setItem(
135+
"apple_oauth_debug",
136+
JSON.stringify(debugInfo),
137+
);
138+
// Also add to window object for console inspection
139+
(window as any).appleOAuthDebug = debugInfo;
140+
} catch (e) {
141+
// Ignore storage errors
142+
}
127143
}
128144

129145
const url = await account!.createOAuth2Session(
@@ -133,18 +149,40 @@ export class AuthService {
133149
);
134150

135151
if (typeof url === "string") {
152+
// Store success info
153+
if (typeof window !== "undefined") {
154+
try {
155+
sessionStorage.setItem("apple_oauth_redirect_url", url);
156+
} catch (e) {
157+
// Ignore storage errors
158+
}
159+
}
136160
window.location.href = url;
137161
}
138162
return { success: true };
139163
} catch (error: any) {
140-
// Enhanced error logging for Apple OAuth
141-
if (process.env.NEXT_PUBLIC_DEBUG_AUTH === "true") {
142-
console.error("Apple OAuth Error:", error);
143-
console.error("Error details:", {
164+
// Store error info for debugging in production
165+
if (typeof window !== "undefined") {
166+
const errorInfo = {
167+
timestamp: new Date().toISOString(),
168+
action: "apple_oauth_error",
144169
message: error.message,
145170
code: error.code,
146171
type: error.type,
147-
});
172+
name: error.name,
173+
stack: error.stack,
174+
};
175+
176+
try {
177+
sessionStorage.setItem(
178+
"apple_oauth_error",
179+
JSON.stringify(errorInfo),
180+
);
181+
// Also add to window object
182+
(window as any).appleOAuthError = errorInfo;
183+
} catch (e) {
184+
// Ignore storage errors
185+
}
148186
}
149187

150188
return {

0 commit comments

Comments
 (0)