# ๐Ÿ”ง AppWrite userId Attribute Fix - Step by Step ## Current Problem โŒ Your AppWrite collections are missing the **critical `userId` attribute**. The error logs show: ``` Invalid query: Attribute not found in schema: userId ``` This happens because the extension tries to filter data by `userId` but the collections don't have this attribute. ## Quick Fix Solution โœ… ### Step 1: Access Your AppWrite Console 1. **Go to**: https://appwrite.webklar.com 2. **Login** with your credentials 3. **Select project**: `6963df38003b96dab5aa` 4. **Navigate to**: Databases โ†’ `amazon-extension-db` ### Step 2: Add userId Attribute to Each Collection You need to add the `userId` attribute to **all 5 collections**: #### Collection 1: `amazon-ext-enhanced-items` 1. **Click** on `amazon-ext-enhanced-items` 2. **Go to** "Attributes" tab 3. **Click** "Create Attribute" 4. **Select** "String" 5. **Enter**: - Key: `userId` - Size: `255` - Required: โœ… **Yes** - Array: โŒ No 6. **Click** "Create" #### Collection 2: `amazon-ext-saved-products` 1. **Click** on `amazon-ext-saved-products` 2. **Go to** "Attributes" tab 3. **Click** "Create Attribute" 4. **Select** "String" 5. **Enter**: - Key: `userId` - Size: `255` - Required: โœ… **Yes** - Array: โŒ No 6. **Click** "Create" #### Collection 3: `amazon_ext_blacklist` 1. **Click** on `amazon_ext_blacklist` 2. **Go to** "Attributes" tab 3. **Click** "Create Attribute" 4. **Select** "String" 5. **Enter**: - Key: `userId` - Size: `255` - Required: โœ… **Yes** - Array: โŒ No 6. **Click** "Create" #### Collection 4: `amazon-ext-enhanced-settings` 1. **Click** on `amazon-ext-enhanced-settings` 2. **Go to** "Attributes" tab 3. **Click** "Create Attribute" 4. **Select** "String" 5. **Enter**: - Key: `userId` - Size: `255` - Required: โœ… **Yes** - Array: โŒ No 6. **Click** "Create" #### Collection 5: `amazon-ext-migration-status` 1. **Click** on `amazon-ext-migration-status` 2. **Go to** "Attributes" tab 3. **Click** "Create Attribute" 4. **Select** "String" 5. **Enter**: - Key: `userId` - Size: `255` - Required: โœ… **Yes** - Array: โŒ No 6. **Click** "Create" ### Step 3: Fix Permissions (Critical!) After adding `userId` attributes, you **must** fix permissions for each collection: **For EACH collection**: 1. **Click** on the collection name 2. **Go to** "Settings" tab (not "Attributes") 3. **Scroll down** to "Permissions" section 4. **Set these exact permissions**: **Create Permission**: - Click "Add a permission" - Select: `users` - Click "Add" **Read Permission**: - Click "Add a permission" - Select: `user:$userId` - Click "Add" **Update Permission**: - Click "Add a permission" - Select: `user:$userId` - Click "Add" **Delete Permission**: - Click "Add a permission" - Select: `user:$userId` - Click "Add" 5. **Click** "Update" to save ## Step 4: Test the Fix โœ… 1. **Reload your Chrome extension** 2. **Go to Amazon**: https://amazon.de/s?k=smartphone 3. **Open browser console** (F12) 4. **Check for errors** - should see no more "userId" errors 5. **Test Enhanced Items** - should work without errors ## Expected Results After Fix โœ… **Console should show**: ``` โœ… AppWrite connection successful โœ… Collections accessible โœ… Real-time sync working โœ… No more "Invalid query: Attribute not found in schema: userId" errors ``` **Extension should work**: - โœ… Enhanced Items panel opens - โœ… Items can be saved to AppWrite - โœ… Data appears in AppWrite console - โœ… Real-time sync between tabs ## Visual Guide ๐Ÿ“ธ ### Finding the Attributes Tab: ``` AppWrite Console โ””โ”€โ”€ Databases โ””โ”€โ”€ amazon-extension-db โ””โ”€โ”€ [Collection Name] โ† Click here โ”œโ”€โ”€ Documents โ”œโ”€โ”€ Attributes โ† Go here to add userId โ””โ”€โ”€ Settings โ† Go here for permissions ``` ### Adding userId Attribute: ``` Attributes Tab โ””โ”€โ”€ Create Attribute โ”œโ”€โ”€ Type: String โ† Select this โ”œโ”€โ”€ Key: userId โ† Enter this โ”œโ”€โ”€ Size: 255 โ† Enter this โ”œโ”€โ”€ Required: โœ… โ† Check this โ””โ”€โ”€ Array: โŒ โ† Leave unchecked ``` ### Setting Permissions: ``` Settings Tab โ””โ”€โ”€ Permissions Section โ”œโ”€โ”€ Create: users โ† Any authenticated user can create โ”œโ”€โ”€ Read: user:$userId โ† Users can only read their own data โ”œโ”€โ”€ Update: user:$userId โ† Users can only update their own data โ””โ”€โ”€ Delete: user:$userId โ† Users can only delete their own data ``` ## Troubleshooting ๐Ÿ”ง **Still getting "userId" errors?** 1. โœ… Make sure you added `userId` to ALL 5 collections 2. โœ… Check that `userId` is marked as "Required" 3. โœ… Verify the attribute name is exactly `userId` (case-sensitive) 4. โœ… Clear browser cache and reload extension **Still getting 401 permission errors?** 1. โœ… Make sure permissions are set correctly for ALL collections 2. โœ… Use `user:$userId` not just `users` for Read/Update/Delete 3. โœ… Try logging out and back in to the extension **Collections not found?** 1. โœ… Make sure you're in the right project: `6963df38003b96dab5aa` 2. โœ… Check database name: `amazon-extension-db` 3. โœ… Collection names must match exactly (case-sensitive) ## Alternative: Use Test Tool ๐Ÿงช Open this file in your browser to automatically test your collections: - `test-appwrite-collections.html` This will tell you exactly which collections are missing the `userId` attribute. ## Why This Happened ๐Ÿค” The collections were created without the `userId` attribute, but the extension code expects it to exist for: - **Data isolation**: Each user only sees their own data - **Security**: Prevents users from accessing other users' data - **Filtering**: All queries filter by `userId` to get user-specific data Adding the `userId` attribute and setting proper permissions fixes this issue permanently.