Skip to content

Commit 13a116c

Browse files
chore: debug Apple & distinguish secrets on environment
1 parent b00a5c6 commit 13a116c

File tree

5 files changed

+53
-7
lines changed

5 files changed

+53
-7
lines changed

.github/workflows/azure-static-web-apps-kind-plant-0e80e5803.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,32 @@ on:
44
push:
55
branches:
66
- main
7+
- 'feature/*'
78
pull_request:
89
types: [opened, synchronize, reopened, closed]
910
branches:
1011
- main
12+
- 'feature/*'
1113

1214
jobs:
1315
build_and_deploy_job:
1416
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
1517
runs-on: ubuntu-latest
1618
name: Build and Deploy Job
19+
environment: ${{ github.ref == 'refs/heads/main' && 'Production' || 'Staging' }}
1720
env:
1821
# Google Analytics
1922
NEXT_PUBLIC_GA_TRACKING_ID: ${{ secrets.NEXT_PUBLIC_GA_TRACKING_ID }}
2023

21-
# Appwrite Configuration
24+
# Appwrite Configuration (comes from environment secrets)
2225
NEXT_PUBLIC_APPWRITE_ENDPOINT: ${{ secrets.NEXT_PUBLIC_APPWRITE_ENDPOINT }}
2326
NEXT_PUBLIC_APPWRITE_PROJECT_ID: ${{ secrets.NEXT_PUBLIC_APPWRITE_PROJECT_ID }}
2427
NEXT_PUBLIC_APPWRITE_API_KEY: ${{ secrets.NEXT_PUBLIC_APPWRITE_API_KEY }}
2528
NEXT_PUBLIC_APPWRITE_DATABASE_ID: ${{ secrets.NEXT_PUBLIC_APPWRITE_DATABASE_ID }}
2629
NEXT_PUBLIC_APPWRITE_DATABASE_NAME: ${{ secrets.NEXT_PUBLIC_APPWRITE_DATABASE_NAME }}
2730
NEXT_PUBLIC_APPWRITE_COLLECTION_ID: ${{ secrets.NEXT_PUBLIC_APPWRITE_COLLECTION_ID }}
2831

29-
# Azure Cosmos DB Configuration
32+
# Azure Cosmos DB Configuration (comes from environment secrets)
3033
AZURE_COSMOSDB_ENDPOINT: ${{ secrets.AZURE_COSMOSDB_ENDPOINT }}
3134
AZURE_COSMOSDB_KEY: ${{ secrets.AZURE_COSMOSDB_KEY }}
3235
AZURE_COSMOSDB_DATABASE: ${{ secrets.AZURE_COSMOSDB_DATABASE }}

AUTHENTICATION_SETUP.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ In your Appwrite project settings, you need to configure callback URLs for OAuth
8282
2. In the Apple OAuth configuration, you'll see a **Redirect URL** field
8383
3. Set this to: `https://yourdomain.com/auth/callback`
8484

85-
**Note**: The success/failure URLs mentioned in the original documentation are not standard Appwrite settings. Appwrite handles OAuth redirects automatically to the redirect URL you specify above. The success/failure parameters are handled by your application logic in the callback route.
85+
**Note**: Since Google OAuth is working with this setup, Apple OAuth should use the same callback URL pattern. However, Apple has additional requirements for domain verification and certificate configuration that Google doesn't have.
8686

8787
## Step 5: Test Authentication
8888

@@ -136,7 +136,17 @@ The authentication flow works seamlessly across all platforms.
136136
3. **Trial timer not working**: Clear localStorage and refresh page
137137
4. **Authentication state not persisting**: Check browser console for errors
138138

139-
### Apple SSO Production Issues
139+
### Apple OAuth Specific Issues
140+
141+
Since Google OAuth is working but Apple OAuth isn't, here are Apple-specific troubleshooting steps:
142+
143+
#### Development vs Production
144+
145+
- **Apple OAuth will NOT work on localhost** - it requires HTTPS and a verified domain
146+
- The code now includes a localhost check that will show a helpful error message
147+
- Always test Apple OAuth in production or staging environment with proper domain
148+
149+
#### Common Apple OAuth Issues
140150

141151
If Apple SSO shows "invalid_request" error in production, check these common causes:
142152

lib/appwrite/auth.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,30 @@ export class AuthService {
102102
}> {
103103
try {
104104
this.checkAppwriteAvailable();
105+
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+
};
119+
}
120+
105121
const redirectUrl = `${window.location.origin}/auth/callback`;
122+
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);
127+
}
128+
106129
const url = await account!.createOAuth2Session(
107130
"apple" as any,
108131
redirectUrl,
@@ -114,6 +137,16 @@ export class AuthService {
114137
}
115138
return { success: true };
116139
} 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:", {
144+
message: error.message,
145+
code: error.code,
146+
type: error.type,
147+
});
148+
}
149+
117150
return {
118151
success: false,
119152
error: {

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.0",
3+
"version": "1.4.1",
44
"private": true,
55
"engines": {
66
"node": "20.x"

0 commit comments

Comments
 (0)