To filter a CMS Collection List by the current user ID using Finsweet attributes and Webhooks in Webflow, you need to combine authentication, user data storage in the CMS, and client-side filtering with Finsweet’s CMS Library.
1. Understand the Architecture
- Webflow CMS does not support native user logins, so use a third-party auth service like Memberstack, Outseta, or Firebase.
- Create a CMS Collection called Users that stores each member's details, including a custom user ID.
- Use Finsweet CMS Library with Attributes to filter other Collection Lists based on the current logged-in user.
2. Set Up User Data in Webflow
- Create a CMS Collection called Users:
- Fields: Name, Email, Slug/UserID, and any other relevant fields.
- In your third-party auth service (e.g., through a signup webhook), create or update the User CMS item when a new member signs up.
3. Trigger Webhooks to Sync User Data
- Use a tool like Zapier, Make (Integromat), or a custom serverless function (e.g., from Firebase or Supabase) to:
- Listen for signup/login events.
- POST user data to the Webflow CMS using Webflow’s CMS API.
- Webflow CMS API requires:
- Site ID.
- Collection ID for the “Users” collection.
- An Authorization header with a Webflow API Token.
4. Identify the Current User in the Frontend
- Once authenticated, the third-party tool should expose the user’s ID or email in the front-end, typically via:
- Custom script injected via a
<script>
tag. - Data attributes added to the DOM (e.g.,
<div id="current-user" data-user-id="12345">
).
5. Filter a CMS Collection Using Finsweet Attributes
- Use the Finsweet Attributes CMS Library:
- Add
fs-cmsfilter-element="list"
to your CMS Collection List. - Add
fs-cmsfilter-field="userId"
to your Collection Item wrapper (the field that stores the user ID). - Use JavaScript to dynamically add a filter:
```js
const userId = document.getElementById("current-user").getAttribute("data-user-id");
window.fsAttributes = window.fsAttributes || [];
window.fsAttributes.push([
'cmsfilter',
(filterInstances) => {
const [filterInstance] = filterInstances;
filterInstance.setFilter('userId', [userId]);
},
]);
``` - Replace
"userId"
with the actual CMS field slug containing the user’s unique identifier.
6. Ensure CMS Relationships Are Accurate
- If you're filtering blog posts by who wrote or owns them:
- In your Blog Posts collection, have a Reference/Multi-Reference field to the Users collection.
- Set the user ID in that field via your webhook when creating posts.
7. Test the Flow
- Log in/sign up as a user through your auth provider.
- Confirm the CMS item for that user gets created or updated.
- Visit the blog page and ensure the Collection List is filtered to show only items with a userId that matches the current logged-in user.
Summary
To filter a CMS Collection List by user ID in Webflow, store user data in a “Users” CMS Collection via third-party signups and Webhooks. Use Finsweet Attributes’ CMS Filter to display personalized content, linking Collection items to unique user IDs and filtering them with JavaScript on the front end.