Skip to content

Commit 61aa3ec

Browse files
Merge pull request #70 from Ditectrev/feature/sso
Apple SSO, Google SSO & Email OTP Sign In/Up
2 parents 01f36c4 + 89099dc commit 61aa3ec

36 files changed

+3852
-2480
lines changed

.env.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
AZURE_COSMOSDB_DATABASE=
22
AZURE_COSMOSDB_ENDPOINT=
33
AZURE_COSMOSDB_KEY=
4+
NEXT_PUBLIC_APPWRITE_API_KEY=
5+
NEXT_PUBLIC_APPWRITE_COLLECTION_ID=
6+
NEXT_PUBLIC_APPWRITE_DATABASE_ID=
7+
NEXT_PUBLIC_APPWRITE_DATABASE_NAME=
8+
NEXT_PUBLIC_APPWRITE_ENDPOINT=
9+
NEXT_PUBLIC_APPWRITE_PROJECT_ID=
10+
NEXT_PUBLIC_GA_TRACKING_ID=

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@ jobs:
1414
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
1515
runs-on: ubuntu-latest
1616
name: Build and Deploy Job
17+
env:
18+
# Google Analytics
19+
NEXT_PUBLIC_GA_TRACKING_ID: ${{ secrets.NEXT_PUBLIC_GA_TRACKING_ID }}
20+
21+
# Appwrite Configuration
22+
NEXT_PUBLIC_APPWRITE_ENDPOINT: ${{ secrets.NEXT_PUBLIC_APPWRITE_ENDPOINT }}
23+
NEXT_PUBLIC_APPWRITE_PROJECT_ID: ${{ secrets.NEXT_PUBLIC_APPWRITE_PROJECT_ID }}
24+
NEXT_PUBLIC_APPWRITE_API_KEY: ${{ secrets.NEXT_PUBLIC_APPWRITE_API_KEY }}
25+
NEXT_PUBLIC_APPWRITE_DATABASE_ID: ${{ secrets.NEXT_PUBLIC_APPWRITE_DATABASE_ID }}
26+
NEXT_PUBLIC_APPWRITE_DATABASE_NAME: ${{ secrets.NEXT_PUBLIC_APPWRITE_DATABASE_NAME }}
27+
NEXT_PUBLIC_APPWRITE_COLLECTION_ID: ${{ secrets.NEXT_PUBLIC_APPWRITE_COLLECTION_ID }}
28+
29+
# Azure Cosmos DB Configuration
30+
AZURE_COSMOSDB_ENDPOINT: ${{ secrets.AZURE_COSMOSDB_ENDPOINT }}
31+
AZURE_COSMOSDB_KEY: ${{ secrets.AZURE_COSMOSDB_KEY }}
32+
AZURE_COSMOSDB_DATABASE: ${{ secrets.AZURE_COSMOSDB_DATABASE }}
1733
steps:
1834
- uses: actions/checkout@v3
1935
with:
@@ -39,8 +55,6 @@ jobs:
3955
app_build_command: "npm run build"
4056
api_build_command: "rm -rf ./node_modules/@next/swc-* && rm -rf ./.next/cache"
4157
###### End of Repository/Build Configurations ######
42-
env:
43-
NEXT_PUBLIC_GA_TRACKING_ID: ${{ secrets.NEXT_PUBLIC_GA_TRACKING_ID }}
4458

4559
close_pull_request_job:
4660
if: github.event_name == 'pull_request' && github.event.action == 'closed'

AUTHENTICATION_SETUP.md

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
# Authentication Setup Guide
2+
3+
This guide will help you set up Appwrite authentication for your Practice Exams Platform.
4+
5+
## Prerequisites
6+
7+
1. An Appwrite account (sign up at [appwrite.io](https://appwrite.io))
8+
2. A new Appwrite project
9+
10+
## Step 1: Create Appwrite Project
11+
12+
1. Log in to your Appwrite console
13+
2. Click "Create Project"
14+
3. Give your project a name (e.g., "Practice Exams Platform")
15+
4. Choose your preferred region
16+
5. Click "Create"
17+
18+
## Step 2: Configure Authentication
19+
20+
### Enable Authentication Methods
21+
22+
1. In your project dashboard, go to **Auth****Settings**
23+
2. Enable the following authentication methods:
24+
- **Email/Password** (for OTP)
25+
- **Google OAuth**
26+
- **Apple OAuth**
27+
28+
### Configure OAuth Providers
29+
30+
#### Google OAuth
31+
32+
1. Go to **Auth****OAuth2 Providers**
33+
2. Click on **Google**
34+
3. Enable the provider
35+
4. Add your Google OAuth credentials:
36+
- Client ID
37+
- Client Secret
38+
5. Set redirect URL: `https://yourdomain.com/auth/callback`
39+
40+
#### Apple OAuth
41+
42+
1. Go to **Auth****OAuth2 Providers**
43+
2. Click on **Apple**
44+
3. Enable the provider
45+
4. Add your Apple OAuth credentials:
46+
- Client ID
47+
- Client Secret
48+
- Team ID
49+
5. Set redirect URL: `https://yourdomain.com/auth/callback`
50+
51+
### Configure Email Templates
52+
53+
1. Go to **Auth****Templates**
54+
2. Customize the email templates for:
55+
- Email OTP verification
56+
- Email verification
57+
58+
## Step 3: Environment Variables
59+
60+
Create a `.env.local` file in your project root with:
61+
62+
```bash
63+
APPWRITE_PUBLIC_ENDPOINT=https://[REGION].cloud.appwrite.io/v1
64+
APPWRITE_PROJECT_ID=your_project_id_here
65+
```
66+
67+
Replace `your_project_id_here` with your actual Appwrite project ID.
68+
69+
## Step 4: Update Callback URLs
70+
71+
In your Appwrite project settings, you need to configure callback URLs for OAuth providers:
72+
73+
### For Google OAuth:
74+
75+
1. Go to **Auth****OAuth2 Providers****Google**
76+
2. In the Google OAuth configuration, you'll see a **Redirect URL** field
77+
3. Set this to: `https://yourdomain.com/auth/callback`
78+
79+
### For Apple OAuth:
80+
81+
1. Go to **Auth****OAuth2 Providers****Apple**
82+
2. In the Apple OAuth configuration, you'll see a **Redirect URL** field
83+
3. Set this to: `https://yourdomain.com/auth/callback`
84+
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.
86+
87+
## Step 5: Test Authentication
88+
89+
1. Start your development server
90+
2. Navigate to any practice or exam page
91+
3. You should see the 15-minute trial timer
92+
4. After 15 minutes, the authentication modal should appear
93+
5. Test all three authentication methods:
94+
- Email OTP
95+
- Google OAuth
96+
- Apple OAuth
97+
98+
## Features Implemented
99+
100+
### Authentication Methods
101+
102+
- **Email OTP**: 6-digit verification code sent via email
103+
- **Google OAuth**: Sign in with Google account
104+
- **Apple OAuth**: Sign in with Apple ID
105+
106+
### Trial System
107+
108+
- **15-minute trial** for unauthenticated users
109+
- **Automatic blocking** after trial expires
110+
- **Persistent trial state** across browser sessions
111+
- **Visual indicators** for trial status
112+
113+
### User Experience
114+
115+
- **Seamless integration** with existing UI
116+
- **Responsive design** for mobile and desktop
117+
- **User profile management** in navigation
118+
- **Automatic redirects** after authentication
119+
120+
## PWA Compatibility
121+
122+
This authentication system is fully compatible with PWA Builder for:
123+
124+
- **Android** deployment
125+
- **iOS** deployment
126+
- **Microsoft Store** deployment
127+
128+
The authentication flow works seamlessly across all platforms.
129+
130+
## Troubleshooting
131+
132+
### Common Issues
133+
134+
1. **OAuth redirect errors**: Ensure callback URLs are correctly configured
135+
2. **Email not sending**: Check Appwrite email service configuration
136+
3. **Trial timer not working**: Clear localStorage and refresh page
137+
4. **Authentication state not persisting**: Check browser console for errors
138+
139+
### Debug Mode
140+
141+
Enable debug logging by adding to your `.env.local`:
142+
143+
```bash
144+
NEXT_PUBLIC_DEBUG_AUTH=true
145+
```
146+
147+
## Security Considerations
148+
149+
- All authentication is handled server-side by Appwrite
150+
- No sensitive credentials are stored in the frontend
151+
- Session management is handled securely by Appwrite
152+
- OAuth tokens are never exposed to the client
153+
154+
## Next Steps
155+
156+
After setup, consider:
157+
158+
1. Adding user profile management
159+
2. Implementing role-based access control
160+
3. Adding analytics for user engagement
161+
4. Setting up email notifications for user actions

0 commit comments

Comments
 (0)