forked from eduardconstantin/azure-cloud-exams
-
-
Notifications
You must be signed in to change notification settings - Fork 22
Apple SSO, Google SSO & Email OTP Sign In/Up #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 10 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6cb4c6d
feat: WIP solution for authentication (issue #24)
danieldanielecki 5291b26
style: update TrialWarning component layout and styling for improved …
danieldanielecki e8d529c
fix: Google SSO
danieldanielecki d3eddec
feat: OTP email sign up/in
danieldanielecki 437cd51
feat: integrate trial with Appwrite w/security trial checks
danieldanielecki 1bc8570
fix: linting errors
danieldanielecki 0957357
fix: environmental variables missing in GitHub actions
danieldanielecki c76fad9
fix: environmental variables missing in GitHub actions + remove some …
danieldanielecki 047be3c
fix: add environmental variables to build stage
danieldanielecki d451f3a
fix: add database name environmental variable which was missing
danieldanielecki 97935c2
fix: give it a shot to have secrets on jobs level
danieldanielecki 5324973
chore: let's debug
danieldanielecki ab1405a
docs: remove lefotver console.logs
danieldanielecki 26fb366
fix: address review comments
danieldanielecki 89099dc
fix: bypassing trial on reload after counting to 0
danieldanielecki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,10 @@ | ||
| AZURE_COSMOSDB_DATABASE= | ||
| AZURE_COSMOSDB_ENDPOINT= | ||
| AZURE_COSMOSDB_KEY= | ||
| NEXT_PUBLIC_APPWRITE_API_KEY= | ||
| NEXT_PUBLIC_APPWRITE_COLLECTION_ID= | ||
| NEXT_PUBLIC_APPWRITE_DATABASE_ID= | ||
| NEXT_PUBLIC_APPWRITE_DATABASE_NAME= | ||
| NEXT_PUBLIC_APPWRITE_ENDPOINT= | ||
| NEXT_PUBLIC_APPWRITE_PROJECT_ID= | ||
| NEXT_PUBLIC_GA_TRACKING_ID= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| # Authentication Setup Guide | ||
|
|
||
| This guide will help you set up Appwrite authentication for your Practice Exams Platform. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| 1. An Appwrite account (sign up at [appwrite.io](https://appwrite.io)) | ||
| 2. A new Appwrite project | ||
|
|
||
| ## Step 1: Create Appwrite Project | ||
|
|
||
| 1. Log in to your Appwrite console | ||
| 2. Click "Create Project" | ||
| 3. Give your project a name (e.g., "Practice Exams Platform") | ||
| 4. Choose your preferred region | ||
| 5. Click "Create" | ||
|
|
||
| ## Step 2: Configure Authentication | ||
|
|
||
| ### Enable Authentication Methods | ||
|
|
||
| 1. In your project dashboard, go to **Auth** → **Settings** | ||
| 2. Enable the following authentication methods: | ||
| - **Email/Password** (for OTP) | ||
| - **Google OAuth** | ||
| - **Apple OAuth** | ||
|
|
||
| ### Configure OAuth Providers | ||
|
|
||
| #### Google OAuth | ||
|
|
||
| 1. Go to **Auth** → **OAuth2 Providers** | ||
| 2. Click on **Google** | ||
| 3. Enable the provider | ||
| 4. Add your Google OAuth credentials: | ||
| - Client ID | ||
| - Client Secret | ||
| 5. Set redirect URL: `https://yourdomain.com/auth/callback` | ||
|
|
||
| #### Apple OAuth | ||
|
|
||
| 1. Go to **Auth** → **OAuth2 Providers** | ||
| 2. Click on **Apple** | ||
| 3. Enable the provider | ||
| 4. Add your Apple OAuth credentials: | ||
| - Client ID | ||
| - Client Secret | ||
| - Team ID | ||
| 5. Set redirect URL: `https://yourdomain.com/auth/callback` | ||
|
|
||
| ### Configure Email Templates | ||
|
|
||
| 1. Go to **Auth** → **Templates** | ||
| 2. Customize the email templates for: | ||
| - Magic URL (email OTP) | ||
| - Email verification | ||
|
|
||
| ## Step 3: Environment Variables | ||
|
|
||
| Create a `.env.local` file in your project root with: | ||
|
|
||
| ```bash | ||
| APPWRITE_PUBLIC_ENDPOINT=https://[REGION].cloud.appwrite.io/v1 | ||
| APPWRITE_PROJECT_ID=your_project_id_here | ||
| ``` | ||
|
|
||
| Replace `your_project_id_here` with your actual Appwrite project ID. | ||
|
|
||
| ## Step 4: Update Callback URLs | ||
|
|
||
| In your Appwrite project settings, you need to configure callback URLs for OAuth providers: | ||
|
|
||
| ### For Google OAuth: | ||
|
|
||
| 1. Go to **Auth** → **OAuth2 Providers** → **Google** | ||
| 2. In the Google OAuth configuration, you'll see a **Redirect URL** field | ||
| 3. Set this to: `https://yourdomain.com/auth/callback` | ||
|
|
||
| ### For Apple OAuth: | ||
|
|
||
| 1. Go to **Auth** → **OAuth2 Providers** → **Apple** | ||
| 2. In the Apple OAuth configuration, you'll see a **Redirect URL** field | ||
| 3. Set this to: `https://yourdomain.com/auth/callback` | ||
|
|
||
| **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. | ||
|
|
||
| ## Step 5: Test Authentication | ||
|
|
||
| 1. Start your development server | ||
| 2. Navigate to any practice or exam page | ||
| 3. You should see the 15-minute trial timer | ||
| 4. After 15 minutes, the authentication modal should appear | ||
| 5. Test all three authentication methods: | ||
| - Email OTP | ||
| - Google OAuth | ||
| - Apple OAuth | ||
|
|
||
| ## Features Implemented | ||
|
|
||
| ### Authentication Methods | ||
|
|
||
| - **Email OTP**: Magic link authentication via email | ||
| - **Google OAuth**: Sign in with Google account | ||
| - **Apple OAuth**: Sign in with Apple ID | ||
|
|
||
| ### Trial System | ||
|
|
||
| - **15-minute trial** for unauthenticated users | ||
| - **Automatic blocking** after trial expires | ||
| - **Persistent trial state** across browser sessions | ||
| - **Visual indicators** for trial status | ||
|
|
||
| ### User Experience | ||
|
|
||
| - **Seamless integration** with existing UI | ||
| - **Responsive design** for mobile and desktop | ||
| - **User profile management** in navigation | ||
| - **Automatic redirects** after authentication | ||
|
|
||
| ## PWA Compatibility | ||
|
|
||
| This authentication system is fully compatible with PWA Builder for: | ||
|
|
||
| - **Android** deployment | ||
| - **iOS** deployment | ||
| - **Microsoft Store** deployment | ||
|
|
||
| The authentication flow works seamlessly across all platforms. | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### Common Issues | ||
|
|
||
| 1. **OAuth redirect errors**: Ensure callback URLs are correctly configured | ||
| 2. **Email not sending**: Check Appwrite email service configuration | ||
| 3. **Trial timer not working**: Clear localStorage and refresh page | ||
| 4. **Authentication state not persisting**: Check browser console for errors | ||
|
|
||
| ### Debug Mode | ||
|
|
||
| Enable debug logging by adding to your `.env.local`: | ||
|
|
||
| ```bash | ||
| NEXT_PUBLIC_DEBUG_AUTH=true | ||
| ``` | ||
|
|
||
| ## Security Considerations | ||
|
|
||
| - All authentication is handled server-side by Appwrite | ||
| - No sensitive credentials are stored in the frontend | ||
| - Session management is handled securely by Appwrite | ||
| - OAuth tokens are never exposed to the client | ||
|
|
||
| ## Next Steps | ||
|
|
||
| After setup, consider: | ||
|
|
||
| 1. Adding user profile management | ||
| 2. Implementing role-based access control | ||
| 3. Adding analytics for user engagement | ||
| 4. Setting up email notifications for user actions | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check with Cursor if Magic URL's are interchengeably called Email OTP's
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 26fb366.