This directory contains the Appwrite-based implementation of the Secure Auth Platform.
| Feature | Appwrite Responsibility |
|---|---|
| Password hashing | ✅ Automatic (Argon2id server-side) |
| Session management | ✅ Secure cookie-based sessions |
| Account creation | ✅ Email/password accounts API |
| Session revocation | ✅ deleteSession('current') |
| Rate limiting | ✅ Built-in per-IP rate limiting |
| Email uniqueness | ✅ Enforced automatically |
| Feature | Our Responsibility |
|---|---|
| Database collection schema | Create attributes, indexes |
| Document-level permissions | Set Permission.read(Role.user(userId)) per document |
| File-level permissions | Set Permission.read(Role.user(userId)) per file |
| Adapter logic | Map API contract to Appwrite SDK calls |
| Data isolation | Configure documentSecurity: true on collection |
- Go to Appwrite Console
- Create a new project
- Note the Project ID
- Generate an API Key (Settings → API Keys) with all scopes enabled
cp .env.example .env
# Edit .env with your Appwrite project detailscd appwrite
npm installnpm run setupnpm run seedIn the testing client:
- Select "Appwrite" mode
- Enter your Appwrite endpoint
- Enter your Project ID
- Enter your Database ID (default:
secure_auth_db) - Enter your Files Collection ID (default:
files) - Enter your Bucket ID (default:
user-files)
Uncomment the Appwrite script tags in index.html:
<script src="https://cdn.jsdelivr.net/npm/appwrite@14.0.0"></script>
<script src="appwrite/web/appwrite-adapter.js"></script>Each file metadata document has permissions:
Permission.read(Role.user(ownerId))— only owner can readPermission.update(Role.user(ownerId))— only owner can updatePermission.delete(Role.user(ownerId))— only owner can delete
This means:
- User A can list and read only their own file documents
- User B cannot see or access User A's documents
- Appwrite enforces this at the server level — no frontend filtering
Each uploaded file has the same permission structure:
- Only the owner can read/download the file
- Appwrite returns 404 for unauthorized access attempts
| Password | |
|---|---|
| alice@example.com | Password123! |
| bob@example.com | Password123! |
| carol@example.com | Password123! |
- The API key is used only by server-side scripts (setup/seed), never exposed to the client
- The adapter uses the Appwrite Web SDK, which authenticates via secure cookies
- Document-level security (
documentSecurity: true) ensures server-enforced isolation - No collection-level read permissions — users can only access their own documents
When testing the Appwrite implementation locally from http://localhost:5500, you might encounter a few quirks related to how Appwrite's security model interacts with your browser:
If you register a new account and attempt to log in immediately, you might get a 401 Unauthorized error (e.g., User missing scope).
Why? Browsers like Chrome (Incognito), Safari, and Brave block Third-Party Cookies by default. Because you are on localhost but hitting an Appwrite Cloud endpoint (nyc.cloud.appwrite.io), your browser drops the session cookie.
Fix: Enable third-party cookies for localhost in your browser settings, or use a standard browser window (not incognito) to test the application.
If you are logged into an account (e.g., alice@example.com), then register a new account (dave@example.com), and attempt to log in to dave, the login will fail.
Why? Appwrite has a strict security constraint: "Creation of a session is prohibited when a session is active." Registration does not automatically log you in, and you cannot log in to a new account while still authenticated as an old one.
Fix: Always click Logout to clear your active session before attempting to log in to a different account.