hope you are well

I am trying to make an app where from the same app, you can either be a user or you can be a seller. In our case, the seller will be a restaurant and the User will be a restaurant-goer. My problem is that if I log in the "I am a restaurant login"-not a user login. On restart the app auto logs in and takes the user to the User homepage, not Seller homepage, as I am using the auth.currentUser != null ?

Then add the home screen or login screen depending on auth state, but it is a general auth state. How would I make it show a different home screen based on the type of Logged in user. So I know why it takes me to the User homepage-I set it to do that, how would I make it takes me to one or the other

thank you

Solution 1: Huthaifa Muayyad

Please post the code you are using for this pathway. I would advise you to create a property called userRole, and store this when the user is created. When you send their name and image and email to Firebase after successful auth, store with that info their userRole.

In your widget tree, I'm assuming you have two widgets, CustomerHome() and RestarauntHome(). Now, after successful login, pass the user info to this widget, and check: user.userRole == 'restaraunt' ? RestarauntHome() : CustomerHome();

This way, when they come back to the app, the page they are not allowed to see, will not be displayed.

Solution 2: beckzile

Assuming you are using firestore database to manage your users' data, in the document of the users collection you can add a field of role whose value could be user or seller. Write to this field when a new user user/seller signs up. Then in the home page, return seller homepage when the value is seller otherwise return the user homepage. While the document is being fetched you can return the loading screen.

Solution 3: Frank van Puffelen

Firebase Authentication has no built-on concept of a type of user, so you will have to build that on top yourself.

You can store the user-type in the user's profile as a custom claim, or in a cloud-hosted database. In either case, you should do this from a secure environment so that user's can't change their type (unless your use-case specifically wants them to be able to).

So with that out of the way your app then takes these steps when started:

  1. signs in the user, or restores their auth state.
  2. determines their type.
  3. redirects them to the correct screen.

Also see: