WARNING: The notes here are not so much a solution, as a discussion of an approach that can be used. It is a very convoluted approach, and at this point, I wouldn't recommend it for use on any client site. You have been warned.
Problem
In our client-side Javascript, we want the UserID of the currently logged-in Memberships User.
It's not available [ 2023-07-13 ], anywhere. Not in script, not in any URL or HTML.
It is in a cookie, buried in an MD5-encoded JWT token, however that cookie is http-only which means our scripts cannot access it.
Solution
PART 1: Make the ID accessible
At present the Membership User _id is only exposed server-side, so you need to make that accessible client-side. For many, the most efficient approach is to duplicate that ID into a custom data field on that same User record.
Here's how to automate that process;
Webflow setup;
- In Webflow, create a custom User Data plain-text field, called user-id
- On your User Account page, add that field to your user account form. You can hide it by placing it inside of a DIV that is display: none. However it must be on the page, and must be in the form.
Automation setup;
- Create a webhook-triggered automation on your favorite automation platform* ( Make, Zapier, n8n... ). When a new user is created, your automation will be called and you’ll have the user’s ID.
- Copy that webhook trigger URL, and use it to setup a Webflow webhook to fire when a new user is created. You want the memberships_user_account_added webhook.
- In your automation, immediately update that same User record, pushing that user_id into a custom Member field you’ve already created. Now, that ID is accessible on the /user-account page as a custom field.
* As of 2023-07-13, Logic unfortunately cannot be used in this situation, since it is unable to call the Webflow API.
PART 2: Access that UserID
Use Sygnal's User Info attributes to access the logged-in user's info, including those custom user fields.
You now have access to the ID.
FAQs
Answers to frequently asked questions.