Understanding Multiple User Types in Bubble
Here's a really quick video in which I'll describe what I think is the best way to handle multiple user types or user roles in Bubble. So I'm building a marketplace app here in this series of tutorials and if I go into data, what I have seen a lot of users do is that they create a new data type. So they might assume that this user is like the shopper and then if they wanted to create a seller, they'd create a new data type here called seller. That's not a great idea because in Bubble the user data type is special compared to any other data types that you create. Only the user data type is able to have the registration, the login and the kind of my account functions. The other data types don't.
Keeping User Data in One Place
So all of your fields to do with users, whether they're sellers or buyers in this case, need to be part of the user data type. Something that I often do is I label my fields in a way that distinguishes whether the field is uniquely one role or the other. So for example, if I wanted to create a seller field, I might label it seller and then put the field name in. Obviously fields like first name, that's going to apply to both sellers and buyers in the context of my marketplace app.
Using Option Sets for User Roles
So how would I distinguish in my Bubble app between the two roles? Well, this is the perfect use of an option set. So I'm going to create an option set called user role and then my two roles are buyer, seller. You could also add in, I'm working on that at the moment where admin is an appropriate role in here because I want to give certain users access to certain areas of my app.
Creating User Role Fields
So that's another way you could use this option set and then in data types, I create a new field for user, user role and then I'm faced with a choice and this will really depend on the type of app you're building. Do you want your user to just be one role and then if they change role, they kind of go from one bucket into another bucket or in this marketplace app, what if I have someone who first of all is a buyer and then they also want to be a seller. I'm thinking along the lines of like an Etsy account or an eBay account allows you to do both but there might be some instances where you just want an account to only be one type but if you want it to be multiple, you can use the list feature here.
Implementing User Roles in the Front End
Great. So if we go on to my front end, just give it a refresh. I have a sign up group focus here and then when the user clicks register, it's going to register them but if I want to make this only for buyers, then I can add in the user role, add buyer. Okay and then I can build a set registration workflow because I have many fields that are different just for my sellers and sellers, I can add them as a buyer and/or add them as a seller at the same time. This also by using as a list, this allows me to easily transition someone who's already got an account and their email addresses in my database from a buyer to a seller.