Restrict app access using user roles in Bubble

You can paywall certain pages or restrict some pages for the Admin using a simple Yes/No field. No plugins or third-party software is needed.

Database setup

You need a Yes/No field in the database which will store the user role value. It can also be a text field if you have multiple tiers like an Admin role, free member, lifetime member etc. To keep things simple, I've chosen a Yes/No field.

I've created field called Paying member and I want to restrict certain pages to only the users who are a member. In short, I need a paywall.

Workflows

Go to the workflow section and click on 'Add an event'. Under the 'General' section, choose 'On page load'.

We'll add a new action in this workflow which will redirect the user away to the Index page if the Paying member field is No.

On the other hand, if the Paying member is Yes, the user will stay on the same page.

The setup is not restricted to a Yes/No field, it's entirely up to you to. You can use a number field, date field, text field or anything else.

Trigger workflows with URL parameters in Bubble.io
You can use URL parameters in Bubble.io to pass information between pages and trigger workflows.

Caveat

ℹ️
There will be a small 1-sec delay before the user is navigated. This is the time Bubble takes to run the workflow. And it's dependent on the user's internet speed also. 

If you have sensitive content on a page, you can either create conditions on the elements to be visible only when the current user's role is correct, or you can create a generic blank loading page. Before going to the restricted page, you can navigate the user to a blank loading and create the above workflows on that page.

This way, the user will only see a blank page while Bubble decides which page the user should be redirected to.

Another solution

As with everything in Bubble, there is no single way to do things. You can do things differently and achieve the same results depending upon your use case.

One alternate method that you can use is instead of using the "On page load" action, you can use the "Do when" condition as well.

Admin privileges and access
You can different user roles in your Bubble.io app. These roles can have different privileges and access to different functions.

Preview - http://nocodeassistant-tutorials.bubbleapps.io/version-test/page_access

Editor - https://bubble.io/page?type=page&name=page_access&id=nocodeassistant-tutorials&tab=tabs-1


If you need some help with your Bubble app, send me an email at himanshu@nocodeassistant.com or follow me on Twitter