Skip to content

Commit f400927

Browse files
fix: display UI text about Apple not handling localhost
1 parent 252d11c commit f400927

File tree

5 files changed

+37
-17
lines changed

5 files changed

+37
-17
lines changed

components/AuthModal.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,19 @@ export const AuthModal: React.FC<AuthModalProps> = ({
124124

125125
const handleAppleSignIn = async () => {
126126
setIsLoading(true);
127+
setMessage(""); // Clear any previous messages
127128
try {
128129
// Save last used method
129130
const method = { type: "apple", value: "Apple" };
130131
setLastUsedMethod(method);
131132
localStorage.setItem("lastUsedAuthMethod", JSON.stringify(method));
132-
await signInWithApple();
133+
const result = await signInWithApple();
134+
135+
if (!result.success && result.error) {
136+
setMessage(result.error);
137+
}
138+
// Always reset loading state
139+
setIsLoading(false);
133140
} catch (error) {
134141
setMessage("Failed to sign in with Apple");
135142
setIsLoading(false);

contexts/AuthContext.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,16 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
9898
};
9999

100100
const signInWithApple = async () => {
101+
console.log("🍎 AuthContext: signInWithApple called");
101102
try {
102103
const result = await AuthService.createAppleSession();
104+
console.log("🍎 AuthContext: createAppleSession result:", result);
103105
return {
104106
success: result.success,
105107
error: result.error?.message,
106108
};
107109
} catch (error: any) {
110+
console.log("🍎 AuthContext: Error in signInWithApple:", error);
108111
return { success: false, error: error.message };
109112
}
110113
};

lib/appwrite/auth.ts

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,29 @@ export class AuthService {
103103
try {
104104
this.checkAppwriteAvailable();
105105

106-
// Check if we're in development (localhost)
107-
if (
108-
typeof window !== "undefined" &&
109-
window.location.hostname === "localhost"
110-
) {
111-
return {
112-
success: false,
113-
error: {
114-
message:
115-
"Apple OAuth requires HTTPS and a proper domain. Please test in production.",
116-
code: 400,
117-
},
118-
};
106+
// Check if we're in development (localhost, 127.0.0.1, or non-HTTPS)
107+
if (typeof window !== "undefined") {
108+
const hostname = window.location.hostname;
109+
const protocol = window.location.protocol;
110+
const isDevelopment =
111+
hostname === "localhost" ||
112+
hostname === "127.0.0.1" ||
113+
hostname.startsWith("192.168.") ||
114+
hostname.startsWith("10.") ||
115+
hostname.startsWith("172.") ||
116+
protocol === "http:" ||
117+
process.env.NODE_ENV === "development";
118+
119+
if (isDevelopment) {
120+
return {
121+
success: false,
122+
error: {
123+
message:
124+
"Apple OAuth requires HTTPS and a proper domain. Please test in production.",
125+
code: 400,
126+
},
127+
};
128+
}
119129
}
120130

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

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "practice-exams-platform",
3-
"version": "1.4.1",
3+
"version": "1.4.2",
44
"private": true,
55
"engines": {
66
"node": "20.x"

0 commit comments

Comments
 (0)