|
| 1 | +--- |
| 2 | +layout: integration |
| 3 | +title: Appwrite Authentication Kit |
| 4 | +description: Seamlessly integrate secure user authentication into your FlutterFlow apps—without writing complex code. |
| 5 | +date: 2024-03-01 |
| 6 | +featured: true |
| 7 | +isPartner: true |
| 8 | +isNew: true |
| 9 | +cover: /images/integrations/flutterflow-auth-kit/cover.png |
| 10 | +category: auth |
| 11 | +product: |
| 12 | + avatar: '/images/integrations/avatars/flutterflow.png' |
| 13 | + vendor: FlutterFlow |
| 14 | + description: 'Appwrite is a secure, open-source backend server for web, mobile, and Flutter developers.' |
| 15 | +platform: |
| 16 | + - 'Self-hosted' |
| 17 | + - 'Cloud' |
| 18 | +images: |
| 19 | + - /images/integrations/flutterflow-auth-kit/cover.png |
| 20 | + - /images/integrations/flutterflow-auth-kit/featured.png |
| 21 | + - /images/integrations/flutterflow-auth-kit/auth-login-overview.png |
| 22 | + - /images/integrations/flutterflow-auth-kit/login-pointers.png |
| 23 | + - /images/integrations/flutterflow-auth-kit/dashboard-pointers.png |
| 24 | +--- |
| 25 | + |
| 26 | +FlutterFlow is a powerful visual builder that lets you create beautiful Flutter apps without writing much code. It's perfect for both beginners and experienced developers who want to build apps quickly. With its drag-and-drop interface and pre-built components, you can focus on creating great user experiences. |
| 27 | + |
| 28 | +# What you’ll build |
| 29 | + |
| 30 | +As you start creating your FlutterFlow app, you might want to add user accounts for things like social media features or task management. To help you with this, we've made it super easy to implement secure authentication using our official [Authentication library](https://marketplace.flutterflow.io/item/h1gn6StcXy6imjg7Ykr2). This guide will walk you through everything you need to know to get up and running with Appwrite authentication in your FlutterFlow project. |
| 31 | + |
| 32 | +By the end of this guide, you’ll have a fully functional authentication system with: |
| 33 | + |
| 34 | +- Email/password sign-up and login. |
| 35 | +- Secure session management. |
| 36 | +- User profile handling. |
| 37 | +- Error handling with user feedback. |
| 38 | +- Protected routes for authenticated users. |
| 39 | + |
| 40 | +Want to see the final result first? Check out our [Appwrite Flutterflow Demo App](https://app.flutterflow.io/project/appwrite-auth-yxmd9b) to experience all these features in action! Then follow along to build your own custom version. |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | +# Before you start |
| 45 | + |
| 46 | +Here’s what you’ll need to have ready: |
| 47 | +- [Appwrite account](https://cloud.appwrite.io/console/register). |
| 48 | +- [FlutterFlow account](https://app.flutterflow.io/create-account). |
| 49 | +- [FlutterFlow Marketplace account](https://marketplace.flutterflow.io/login) (must use the same email as your FlutterFlow account). |
| 50 | +- Basic understanding of FlutterFlow’s interface. |
| 51 | + |
| 52 | +## Step 1: Setting up your Appwrite project |
| 53 | + |
| 54 | +Let’s start by setting up your Appwrite project (you can use a new or an existing one): |
| 55 | + |
| 56 | +1. Head over to the [Appwrite Console](https://cloud.appwrite.io/). |
| 57 | +2. Select your project (or create a new one). |
| 58 | +3. Under **Add a platform**, add a **Flutter** platform. |
| 59 | +4. In the platform setup, choose the platforms you want to support under Flutter App - Web, Android, and/or iOS - and enter the required values as shown below: |
| 60 | + |
| 61 | + |
| 62 | +| Platform | Required Info | |
| 63 | +|----------|----------------| |
| 64 | +| Web | Hostnames: `localhost`, `*.web.app`, `*.run.app` (Used for FlutterFlow Web Testing) | |
| 65 | +| Android | Package Name (e.g. `com.company.appname`) | |
| 66 | +| iOS | Bundle ID (e.g. `com.company.appname`) | |
| 67 | + |
| 68 | +5. Go to **Settings > Overview** to copy the following values: |
| 69 | +- **API Endpoint** |
| 70 | +- **Project ID** |
| 71 | + |
| 72 | +📌 You’ll need these in the next step to configure the authentication library. |
| 73 | + |
| 74 | + |
| 75 | +## Step 2: Adding the authentication library |
| 76 | + |
| 77 | +The Authentication library provides essential core functionality: |
| 78 | + |
| 79 | +- Pre-configured Custom Actions for authentication. |
| 80 | +- App States for session management. |
| 81 | +- Built-in Error Handling. |
| 82 | +- User Session Management. |
| 83 | +- Custom Data Types for type-safe responses. |
| 84 | + |
| 85 | +### Here’s how to add it to your project: |
| 86 | + |
| 87 | +1. Visit the [FlutterFlow Marketplace](https://marketplace.flutterflow.io/). |
| 88 | +2. Search for “Appwrite Authentication Kit” or visit [Appwrite Authentication Kit](https://marketplace.flutterflow.io/item/h1gn6StcXy6imjg7Ykr2). |
| 89 | +3. Click “Add” to add it to your marketplace account. |
| 90 | +4. In your FlutterFlow project: |
| 91 | + |
| 92 | + - Navigate to `Project Settings > Project Dependencies`. |
| 93 | + - Find “Appwrite Authentication Kit” under FlutterFlow Libraries. |
| 94 | + - Click “Add Library”. |
| 95 | + |
| 96 | + |
| 97 | + |
| 98 | +### Configure the Authentication Library |
| 99 | + |
| 100 | +Once the library is added, you can configure it without writing any code: |
| 101 | + |
| 102 | +1. Navigate to `Settings > Project Dependencies` in your FlutterFlow project. |
| 103 | +2. Under the **Appwrite Authentication Kit** entry, click on **View Details**. |
| 104 | +3. Update the environment values directly in the panel that opens: |
| 105 | + |
| 106 | +- API Endpoint: `Your Appwrite Project Endpoint` |
| 107 | +- Project ID: `Your Appwrite Project ID` |
| 108 | + |
| 109 | +Note: This view opens automatically the first time a user adds the library - making it super easy to update values right away. |
| 110 | + |
| 111 | + |
| 112 | +## Step 3: Understanding the components |
| 113 | + |
| 114 | +The library sets up two essential app states: |
| 115 | +- `appwriteConfig`: Stores configuration details securely. |
| 116 | +- `appwriteUser`: Manages user session information. |
| 117 | + |
| 118 | +Both states are automatically configured with: |
| 119 | + |
| 120 | +- String data type. |
| 121 | +- Persistence enabled. |
| 122 | +- Authentication flow readiness. |
| 123 | + |
| 124 | +### Custom Data Types: |
| 125 | + |
| 126 | +The library provides two custom data types for type-safe responses: |
| 127 | + |
| 128 | +1. `AppwriteUser`: Represents user data. |
| 129 | + - Fields: id, email, name, emailVerified, status. |
| 130 | + - Used for: Storing and passing user information. |
| 131 | + |
| 132 | +2. `AppwriteUserResponse`: Standard response format. |
| 133 | + - Fields: success, error, errorCode, errorType, formattedError, user. |
| 134 | + - Used for: Consistent error handling and success responses. |
| 135 | + |
| 136 | +### Authentication actions: |
| 137 | + |
| 138 | +The library provides five essential custom actions: |
| 139 | + |
| 140 | +1. `initialize` |
| 141 | + - Purpose: Sets up your Appwrite configuration. |
| 142 | + - Returns: `AppwriteUserResponse` with initialization status. |
| 143 | + - Must be called before any other authentication action. |
| 144 | + |
| 145 | +2. `signUpWithEmailAndPassword` |
| 146 | + - Parameters: email, password. |
| 147 | + - Returns: `AppwriteUserResponse` with user data. |
| 148 | + - Handles: Account creation and session setup. |
| 149 | + |
| 150 | +3. `signInWithEmail` |
| 151 | + - Parameters: email, password. |
| 152 | + - Returns: `AppwriteUserResponse` with session data. |
| 153 | + - Manages: User login process. |
| 154 | + |
| 155 | +4. `signOut` |
| 156 | + - No parameters required. |
| 157 | + - Returns: `AppwriteUserResponse` with success status. |
| 158 | + - Handles: Complete session cleanup. |
| 159 | + |
| 160 | +5. `getCurrentUser` |
| 161 | + - No parameters required. |
| 162 | + - Returns: `AppwriteUserResponse` with current user data. |
| 163 | + - Perfect for: Authentication state checks. |
| 164 | + |
| 165 | +### Understanding action flows: |
| 166 | + |
| 167 | +Each authentication action follows this consistent pattern: |
| 168 | + |
| 169 | +1. Action execution. |
| 170 | +2. Response handling using `AppwriteUserResponse`. |
| 171 | +3. Success/failure conditions based on `response.success`. |
| 172 | +4. Error handling using `response.formattedError`. |
| 173 | + |
| 174 | + |
| 175 | + |
| 176 | + |
| 177 | +### Example: Sign Up flow |
| 178 | + |
| 179 | +1. Use the `signUpWithEmailAndPassword` action. |
| 180 | +2. Check `signUpResult.success`. |
| 181 | +3. Success? → Dashboard. |
| 182 | +4. Failure? → Show `signUpResult.formattedError`. |
| 183 | + |
| 184 | +You can use `response.error` for internal logging and `response.formattedError` to display user-friendly messages. Similarly, you can implement flow patterns for other authentication actions (`signInWithEmail`, `signOut`, `getCurrentUser`), following the similar structure of checking results and handling success/failure scenarios appropriately. |
| 185 | + |
| 186 | +## See it in action |
| 187 | + |
| 188 | +Check out our [Appwrite FlutterFlow Demo App](https://app.flutterflow.io/project/appwrite-auth-yxmd9b) to explore the complete auth flow in action - from sign-up to session management. |
| 189 | + |
| 190 | + |
| 191 | +## Troubleshooting common issues |
| 192 | + |
| 193 | +1. **Library Not Found** |
| 194 | + - Verify marketplace account email matches FlutterFlow account. |
| 195 | + - Check if library is properly added in Project Dependencies. |
| 196 | + |
| 197 | +2. **Authentication Failures** |
| 198 | + - Confirm `initialize` action is called first. |
| 199 | + - Verify endpoint and projectId values. |
| 200 | + - Check Appwrite console for platform settings. |
| 201 | + |
| 202 | +3. **Session Management Issues** |
| 203 | + - Ensure app states are properly configured. |
| 204 | + - Verify persistence settings. |
| 205 | + |
| 206 | +This completes our guide on setting up Appwrite authentication in your FlutterFlow app. You now have a solid foundation for managing user accounts and secure sessions. |
| 207 | + |
| 208 | +Now that you have the basics in place, you can enhance your app by implementing more advanced authentication features using Appwrite. If you run into any issues or have questions, the [Appwrite community on Discord](https://appwrite.io/discord) and the [FlutterFlow Community](https://community.flutterflow.io/) are always ready to help. Don't hesitate to reach out! |
| 209 | + |
| 210 | +## More resources |
| 211 | + |
| 212 | +If you would like to learn more about Appwrite and FlutterFlow, we have some resources that you should visit: |
| 213 | + |
| 214 | +- [Appwrite Flutterflow Demo App](https://app.flutterflow.io/project/appwrite-auth-yxmd9b) |
| 215 | +- [Appwrite Documentation](https://appwrite.io/docs) |
| 216 | +- [FlutterFlow Marketplace](https://marketplace.flutterflow.io/item/h1gn6StcXy6imjg7Ykr2) |
0 commit comments