Skip to main content

Dynamic apps using hex_user_email

A dive into the hex_user_email built-in variable and how to leverage it to create dynamic apps.

tip

Check out the companion Hex project for this tutorial here!

This tutorial will go into detail on the hex_user_email built-in variable, and cover some examples for creating dynamic app experiences based on the its value. By the end, you'll be ready to create a single app that renders differently depending on who's viewing the published app!

What is hex_user_email?

Hex has a few built-in variables that can be leveraged in the logic of your projects. One of these built-in variables is hex_user_email.

In published apps, the logged in user's email address will be stored as the hex_user_email variable. This makes this variable perfect for customizing what a given user sees in the app!

Some example use cases

SELECT account, sum(revenue)
FROM sales_table
WHERE account_owner_email == {{hex_user_email}}
  • Execute dynamic Python code:
if hex_user_email in ('[email protected]', '[email protected]', '[email protected]'):
department = 'engineering'
else:
department = 'other'
{% if hex_user_email == '[email protected]' %}
Hi Jaylin!
{% elif hex_user_email == '[email protected]' %}
Hi Imani!
{% else %}
Hi there!
{% endif %}

Something important to note about the use of hex_user_email is that the Cache Default State app setting must be turned off in order for the app's initial load to run as expected.

Why? When Cache Default State is on, the app automatically loads using the cached results from the most recent app publish/scheduled run. Therefore, if you want hex_user_email to be set to the viewer's email address upon the app's initial load, this setting will need to be off.

hex_user_email in different run contexts

Note: hex_user_email will only evaluate to the user's email address in the published app.

When viewing the project's Logic + App Builder, the variable will always equal [email protected].

If an anonymous user (i.e., someone without a Hex account) views the published App, hex_user_email will be a random hash. An app will only ever have anonymous viewers if it's been made available publicly.

tip

Check out this tutorial's companion app to see how the hex_user_email value changes when viewing the logic vs. the published app.

Video example

To drive this home, here's a quick video demo of what a published app that uses hex_user_email looks like from the perspectives of two different users!