GithubHelp home page GithubHelp logo

Comments (8)

Milad-Akarie avatar Milad-Akarie commented on June 11, 2024 1

@realitymolder share your existing implementation using declarative.
fyi it's only deprecated in root scope, you can still use declarative in sub-routers

from auto_route_library.

realitymolder avatar realitymolder commented on June 11, 2024 1

@realitymolder share your existing implementation using declarative. fyi it's only deprecated in root scope, you can still use declarative in sub-routers

I used it in root, as a routerDelegate:

   routerDelegate: AutoRouterDelegate.declarative(
          _appRouter,
          routes: (_) {
            return auth.when(
              data: (authState) {
                return authState.when(
                  finished: () {
                    ref
                        .read(userControllerProvider.notifier)
                        .getAuthenticatedUser();
                    // if they are logged in and finished , bring them to the Home page:
                    return [const HomeRoute()];
                  },
                  onboarding: () {
                    // if they are logged in but didnt finish , bring them to the Onboarding page
                    return [const OnboardingRoute()];
                  },
                  unAuthenticated: () {
                    // if they are not logged in, bring them to the Login page
                    return [const LoginRoute()];
                  },
                );
              },
          error: (e, s) => [const ErrorRoute()],
          loading: () => [const LoadingRoute()],
        );
        },
        ),
        routeInformationParser:
            _appRouter.defaultRouteParser(includePrefixMatches: true),

from auto_route_library.

mxknt avatar mxknt commented on June 11, 2024 1

@Milad-Akarie Just want to tag along and say that I'm using AutoRouter the exact same way, with a declarative router at the root of my app to handle the auth state. Also curious what the alternative is if this pattern is being deprecated. Thanks for all your work on this awesome library!

from auto_route_library.

Milad-Akarie avatar Milad-Akarie commented on June 11, 2024 1

@realitymolder @mxknt you had no problems with deep-linking when working with the root declarative router?

from auto_route_library.

Milad-Akarie avatar Milad-Akarie commented on June 11, 2024 1

@realitymolder what you can do is have a sub-router dedicated to auth-flow and guard your home route with an auth guard

from auto_route_library.

realitymolder avatar realitymolder commented on June 11, 2024

@Milad-Akarie

from auto_route_library.

realitymolder avatar realitymolder commented on June 11, 2024

@realitymolder @mxknt you had no problems with deep-linking when working with the root declarative router?

This is a new project, so didn't have a chance yet to get into deep linking. Also, my implementation of the router delegate (root) was very young, and I tried to go with the "best practice" to make sure I solve this issue in the best way possible.
With that said, It is quite an issue due to the fact that it's not a boolean auth but a Tri auth situation and 2 of those are dependent on an async value that comes from the server...

from auto_route_library.

realitymolder avatar realitymolder commented on June 11, 2024

@realitymolder what you can do is have a sub-router dedicated to auth-flow and guard your home route with an auth guard

I'm trying to implement that now, but it seems like I'm not able to update the state of the guard, like the guard is not listening, although I'm using .watch (riverpod)
Only on hot reload, the app will show the relevant event
example:

class AuthGuard extends AutoRouteGuard {
  AuthGuard({required this.ref});
  final Ref ref;

  @override
  void onNavigation(NavigationResolver resolver, StackRouter router) {
    ref.read(authControllerProvider.notifier).loadAuthState();

    logger.d('message from AuthGuard');
    ref.watch(authControllerProvider).when(
          data: (authState) {
            authState.when(
              unAuthenticated: () {
                
                logger.d('unAuthenticated');
                // resolver.redirect(const LoginRoute());
                router.popAndPush(const LoginRoute());
              },
              onboarding: () {
                logger.d('onboarding');
                router.popAndPush(const OnboardingRoute());
                
                // resolver.next(false);
              },
              finished: () {
                logger.d('finished');
                resolver.next();
              },
            );
          },
          error: (error, stackTrace) =>
              logger.e(error.toString(), stackTrace: stackTrace),
          loading: () {
            logger.d('Loading AuthGuard...');
            // ref.read(authControllerProvider.notifier).loadAuthState();
          },
        );
  }
}

from auto_route_library.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.