Run As A User From The Front End?

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

  1. Select your main page element (the root folder/container of your SPA).

  2. Open the element inspector (i) and click Add a new custom state.

  3. Name it Impersonated Tenant.

  4. 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”.

  1. Start a workflow on that button.

  2. Choose Element Actions > Set State.

  3. Element: [Your Main Page]

  4. Custom State: Impersonated Tenant

  5. 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.

  1. Set the conditional on this banner: When Main Page's Impersonated Tenant is not empty $\rightarrow$ This element is visible (checked).

  2. Put a text box inside it saying: “You are currently viewing the portal as Main Page's Impersonated Tenant's Name.”

  3. Add a button next to it labeled “Exit View Mode”.

  4. Set the workflow for that exit button to: Set State Impersonated 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.

Check this post by George Collier:

Thanks, George.

You’re making this seem too easy.

I actually searched the forum and didn’t see this solution.

Thank you so much :slightly_smiling_face:

I’d described it on a post somewhere but also couldn’t find it, so the X post will have to suffice!

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.

 
 

Thank you for the update.

I will definitely look into this.

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.

Thanks again

There is a very easy way to do this. Simply use the “Open an external website” workflow action and enter the following URL:

https://bubble.io/appeditor/authenticate_as/APPID/test/UNIQUE_ID/true/index’.

APP_IDis your App’s id,

UNIQUE_ID is the unique ID of the user you want to log in as,

test is the app version (test or live),

index is the page the user will be redirected to after logging in.

Please note: triggering this action logs out your current user account to log in to the new account.

Yeah, but you need editor access for that to work.