在 Flutter 中使用相同的 Firebase 在同一个应用中分离用户和卖家

在 Flutter 中使用相同的 Firebase 在同一个应用中分离用户和卖家

问题描述:

希望你一切都好

我正在尝试从同一个应用程序制作一个应用程序,您可以是用户,也可以是卖家.在我们的例子中,卖家将是一家餐厅,而用户将是餐厅的常客.我的问题是,如果我登录我是餐厅登录",而不是用户登录.在重新启动应用程序时自动登录并将用户带到用户主页,而不是卖家主页,因为我正在使用auth.currentUser != null ?

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

谢谢

请发布您用于此途径的代码.我建议您创建一个名为 userRole 的属性,并在创建用户时存储它.当您在成功进行身份验证后将他们的姓名、图片和电子邮件发送到 Firebase 时,请使用该信息存储他们的 userRole.

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.

在您的小部件树中,我假设您有两个小部件,CustomerHome() 和 RestarauntHome().现在,成功登录后,将用户信息传递给这个小部件,并检查:user.userRole == 'restaraunt' ?RestarauntHome() : CustomerHome();

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.