## Add Hanko to Mobile Applications**Purpose:** Enforce only the **current** and **correct** instructions for integrating [Hanko](https://hanko.io/) passwordless authentication into native mobile applications (iOS/Android). **Scope:** All AI-generated advice or code related to Hanko mobile integration must follow these guardrails for direct API integration.---## **1. Official Hanko Integration Overview**Use only the **current** approach from Hanko's documentation:- **Use direct API calls** to Hanko's REST endpoints (no native SDKs available yet)- **Check user existence** using the `/users` endpoint before creating- **Create users** via POST to `/users` endpoint when they don't exist- **Send passcodes** using `/passcode/login/initialize` endpoint- **Verify passcodes** using `/passcode/login/finalize` endpoint - **Handle JWT tokens** returned in X-Auth-Token header or cookies- **Implement passkeys** using native iOS/Android WebAuthn APIs (iOS 16+, Android 9+)- **Configure APK Key Hash** for Android passkey support- **Validate tokens** on backend using session validation endpoints---## **2. CRITICAL INSTRUCTIONS FOR AI MODELS**### **2.1 – ALWAYS DO THE FOLLOWING**1. **Check user existence first** using GET `/users?email={email}` before creating2. **Handle both 200 and 404 responses** for user existence checks3. **Store user ID** from responses for subsequent API calls4. **Use POST method** for user creation and passcode operations5. **Send JSON payloads** with proper Content-Type headers6. **Handle JWT tokens** from X-Auth-Token header or cookies7. **Use native WebAuthn APIs** for passkey implementation (iOS/Android)8. **Configure APK Key Hash** for Android passkey support9. **Validate tokens on backend** using session validation10. **Implement proper error handling** for all HTTP status codes### **2.2 – NEVER DO THE FOLLOWING**1. **Do not** skip user existence check before creating users2. **Do not** use passwords in mobile integration (passwordless only)3. **Do not** assume native SDK availability (use direct API calls)4. **Do not** ignore HTTP status codes in API responses5. **Do not** hardcode API URLs in production code6. **Do not** skip error handling for network requests7. **Do not** attempt passkeys on unsupported OS versions8. **Do not** forget APK Key Hash configuration for Android---## **3. CORRECT IMPLEMENTATION PATTERNS**### **User Existence Check**```httpGET /users?email=user@example.comHeaders: Content-Type: application/jsonResponse 200 (User exists):{ "id": "user-uuid-here", "email": "user@example.com"}Response 404 (User doesn't exist):{ "code": 404, "message": "user not found"}
// ❌ DO NOT skip user existence checkconst createUser = await fetch('/users', { method: 'POST', body: JSON.stringify({ email: userEmail })}); // Should check existence first// ❌ DO NOT ignore HTTP status codesconst response = await fetch('/passcode/login/finalize', requestOptions);const data = await response.json(); // Should check response.status first// ❌ DO NOT use passwords in mobile flowconst loginData = { email: userEmail, password: userPassword // Hanko is passwordless only};// ❌ DO NOT attempt passkeys on unsupported versionsif (iOS < 16 || Android < 9) { // Still trying to use passkeys - should check version first createPasskey(options);}// ❌ DO NOT forget APK Key Hash for Android// Missing APK Key Hash configuration will cause Android passkeys to fail// ❌ DO NOT hardcode API URLsconst response = await fetch('https://hardcoded-url.hanko.io/users');