Authenticate with Go Router and BLoC in flutter
I am using Go Router together with BLoC in a web app to manage the user session. What I am looking for is that, at the moment of entering a certain route, to be able to validate if a user is authenticated. Inside the BLoC I have a function that validates if a token exists (it returns “false” or “true”).
My problem is that, in the case of refreshing the page, the path logic is executed first and then the BLoC logic is executed. Then, if there is a user already logged in, the path guard will take the initial state of “isAuth” which is false, but then if it will be true, since a token does exist.
What can I do?