Appwrite Backend
[!NOTE] Important Info ❗ If
enableAppwriteis set to true, a internet connection is required for using the app
1. Create the Project on Appwrite
- Sign in to the Appwrite console and create a new project.
- Add the React Native project to Appwrite.
- Include the iOS App ID and Android package name.
2. Set Up the Database
- Create a new database.
- Design and create attributes, relationships, and collections as needed.
- Set Access Permissions: Ensure proper access rules are defined for reading and writing data.
- In the Settings tab of each collection, configure permissions.
- Allow users to Create, Read, Update, and Delete their own documents.
- Set appropriate roles (e.g.,
user:$idfor individual access,team:$idfor group access).
3. Configure Appwrite Settings
Configure your Appwrite connection in config/appwrite.js. This file contains all the settings needed to connect to your Appwrite backend:
config/appwrite.js
const config = {
// Your Appwrite project ID (found in Appwrite console)
projectId: "",
// Your Appwrite endpoint (e.g., "https://cloud.appwrite.io/v1")
endpoint: "",
// Your Appwrite database ID
db: "",
// Platform-specific identifiers for Appwrite SDK
platform: {
// iOS bundle identifier (e.g., "com.yourcompany.yourapp")
bundleId: "",
// Android package name (e.g., "com.yourcompany.yourapp")
packageName: "",
},
// Collection IDs for different features. Create these collections in your Appwrite database
col: {
expoPushTokens: "",
},
}
export { config };5. Store Values in Appwrite
Use the following function to store values in a specific collection:
config/appwrite.js
const storeValue = async (collection, data) => {
try {
const document = await database.createDocument(
config.db,
collection,
"unique()",
data
);
console.log("Value stored:", document);
} catch (error) {
console.log("Error storing value:", error);
setError(error);
}
};6. Automate with Functions
Appwrite Functions can be used to automate tasks such as sending push notifications and emails. Set up functions in the Appwrite Functions page to handle background tasks efficiently.