lucavenir / go_router_riverpod

An example on how to use Riverpod + GoRouter
469 stars 70 forks source link

Login not working when using flutter_web_auth #27

Closed masewo closed 1 year ago

masewo commented 1 year ago

When I try to add the flutter_web_auth dependency to the login method, then no login is happening on the web platform. It seems like the build method AuthNotifier is triggered again (because of the new opened and then closing tab) and the bulid method of RouterNotifier is not triggered. Tried to set keepAlive: true but it did not help.

When you hot restart the app, then you are logged in.

Running following code for the web platform fails:

Example code:

  /// Mock of a successful login attempt, which results come from the network.
  Future<void> login(String email, String password) async {
    state = await AsyncValue.guard<User>(() async {
      String webCallbackUrlScheme =
          'http://localhost:5000/auth.html';
      String callbackUrlScheme = 'de.demo.auth';
      await FlutterWebAuth2.authenticate(url: webCallbackUrlScheme, callbackUrlScheme: callbackUrlScheme);

      return Future.delayed(
        networkRoundTripTime,
        () => _dummyUser,
      );
    });
  }
masewo commented 1 year ago

Nevermind, my bad.

I thought I narrowed it down to a problem related to the fact, that flutter_web_auth opens a new tab on the web platform, causing an unwanted rebuild (that I didn't see happen in the code_gen example), but it also seemed connected to the assumption, that more than one AuthNotifier or RouterNotifier might exist.

But I did not see the problem happen with an example using a simple html.open.

At the end I - as a riverpod beginner - found my main problem:

Also there were some side problems, which were causing confusions on my side while analysing the problem:

Hope this might help someone in the future - or my future I...