On my property management app, I want to let the property manager be able to run as a user for various reasons… troubleshooting, etc.
I realize it is possible through the backend, but I want to just do a button on the tenant page where they can click it and run as the tenant without needing to log in to the backend and all.
This has been perplexing, and I think I’m wasting a lot of time trying to figure out if it is possible.
Here is what AI has told me, but I’m not sure this is even right.
Can someone look at this and tell me if AI is hallucinating or if this is worth trying? I’ve tried several different things so far, and I’m getting frustrated:
Step 1: Create a Custom State on your Page
Select your main page element (the root folder/container of your SPA).
Open the element inspector (i) and click Add a new custom state.
Name it Impersonated Tenant.
Set the State Type to User. (Leave it empty by default).
Step 2: The “View As” Button Workflow
On your manager dashboard, inside the repeating group of tenants, add a button that says “View Portal”.
Start a workflow on that button.
Choose Element Actions > Set State.
Element: [Your Main Page]
Custom State: Impersonated Tenant
Value: Current cell's User
Step 3: Update Your UI Display Logic
Right now, your tenant dashboard elements are probably pulling data by looking at Current User's [Lease/Data]. You just need to tweak those data sources to look for the impersonated state first.
Whenever you display tenant-specific info, use a conditional expression like this:
Data Source:Main Page's Impersonated Tenant is not empty $\rightarrow$ use Main Page's Impersonated Tenant
Fallback: If it is empty, use Current User
Step 4: The “Exit Impersonation” Banner
You want to make sure the manager doesn’t get stuck in tenant mode. Add a floating group bar or banner at the very top of the page that is hidden by default.
Set the conditional on this banner: When Main Page's Impersonated Tenant is not empty $\rightarrow$ This element is visible (checked).
Put a text box inside it saying: “You are currently viewing the portal as Main Page's Impersonated Tenant's Name.”
Add a button next to it labeled “Exit View Mode”.
Set the workflow for that exit button to: Set StateImpersonated Tenant $\rightarrow$ Value: clear / leave blank.
This approach keeps your workflows clean and ensures that when the property manager clicks “Exit View Mode”, they instantly drop right back into their manager panel without needing to type passwords or log back in.
FWIW, with the ability we now have to return data directly from the backend to the frontend (as announced in this recent demo / Q&A by Josh and Emmanuel), there’s no need for an API Connector call; so it’s even simpler. Just return the login link and visit it using the Open an external website action.
A couple of important notes though…
Make sure there’s a condition on the “Log in as” button’s workflow which checks that the current user has the appropriate permissions (e.g. Current User's Roles contains Admin). In your case, if you’re running a multi-tenant SaaS, this might entail checking if the person the property manager is attempting to “impersonate” is actually one of their tenants. It’s also advisable to protect the backend custom event with a condition as well.
When generating the login link, I would also suggest minimizing the potential “attack surface” by setting the link expiration to a fractional value. I generally use 0.005, which is 18 seconds.
My thinking on this is that, instead of having the property manager or someone else from their office log in to the backend of Bubble (which they have no idea how to use)…
it would be better if they could just ‘run as’ to help that rare tenant that, no matter how easy you try and make things, still can’t understand how to do something.
The property manager can create a lease in the app, and the tenant can simply log in to add their signature and initials to finalize the lease.
However, no matter how big the arrows or flashing neon signs that say sign here, or initial here (yes, slightly exaggerating), there are still those individuals who don’t have the slightest idea of anything technical. They’re rare, but they’re out there, and we’ve come across a few of them.