The 'Set Browser Cookie' action allows you to store data in a user’s browser for long-term access, beyond just the current session. Unlike the 'Update Local State' action, which resets when the user refreshes or logs out, cookies persist across sessions, making them useful for remembering user preferences, authentication tokens, or other key data between visits.
Setting Up 'Set Browser Cookie'
To configure a browser cookie in Frontly:
Key – Enter a unique identifier for the cookie (e.g., loginToken).
Value – Assign the data you want to store (e.g., {{time.now}} ).
Expiry Time (hours) – Define how long the cookie remains valid before expiration. Leaving this empty defaults to a session cookie (deleted when the browser closes).
Run Conditions (Optional) – Add conditions to control when the cookie is set.
Once stored, the cookie's value can be accessed using {{ cookies.custom_key }}, where custom_key is the name assigned in the Key field.
Benefits & Considerations
Why Use Cookies?
✅ Persistence: Retain data even after the user refreshes or logs out.
✅ Personalization: Store user settings or preferences for a better experience.
✅ Session Management: Track login states or other session-relevant data.
Things to Keep in Mind
⚠ Security: Avoid storing sensitive information (e.g., passwords) in cookies, as they are accessible via the browser.
⚠ Expiration Handling: Set expiry times carefully to ensure proper data lifecycle management.
⚠ Privacy Regulations: Be mindful of data privacy laws (e.g., GDPR, CCPA) if using cookies to track user behavior.
The 'Set Browser Cookie' action provides an easy way to persist data across sessions, improving the functionality and user experience of your Frontly app. Try it out and enhance your app’s state management today!