You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm developing a web app using Flutter Web and Firebase.
I have to handle the Firebase Login.
Let's assume we have two screens (login and homepage), the situation that I want to achieve is the following:
if the user is not logged in:
Whatever url he types in the web, redirect the user on the login page
If the user is not logged in:
if he lands on the login page, redirect him on the homepage
if he lands on any other pages, stay on that page
I've implemented a functions that checks the current user in firebase and acts as following:
void checkAuthentication() {
var url = window.location.href;
var navigationService = locator<NavigationService>();
var loggedIn = this.isUserLoggedIn();
if (!loggedIn) {
navigationService.replaceWith(Routes.login);
} else {
if (url.contains("Login")) {
navigationService.replaceWith(Routes.homepage);
}
}
}
This solution works, but has two problems:
This is not the right approach to do this. It's not possible that I have to call this in each screen page
When you are redirected you can see a transition with the new page presented.
My question: How would you manage this in Flutter Web in a unique point in the code? Is there a better way to achieve this different from the one I shown here?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm developing a web app using Flutter Web and Firebase.
I have to handle the Firebase Login.
Let's assume we have two screens (login and homepage), the situation that I want to achieve is the following:
if the user is not logged in:
If the user is not logged in:
I've implemented a functions that checks the current user in firebase and acts as following:
This solution works, but has two problems:
This is not the right approach to do this. It's not possible that I have to call this in each screen page
When you are redirected you can see a transition with the new page presented.
My question: How would you manage this in Flutter Web in a unique point in the code? Is there a better way to achieve this different from the one I shown here?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions