Comments (8)
@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 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.
@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.
@realitymolder @mxknt you had no problems with deep-linking when working with the root declarative router?
from auto_route_library.
@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.
from auto_route_library.
@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 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)
- didPop & didPopNext not called
- IOS swipe back make TextField not focus when tab on TextField when app build with flutter 3.22 HOT 2
- CustomRoute() transition gets overridden by defaultRouteType
- Handling of back navigation in nested routes, ignored PopScope HOT 2
- pushing to same screen issue
- New Xcode error out of the blue
- [Bug] - Using the same Screen as Two routes results into an exception
- [QUESTION] Why RouteMatch operator == doesn't have args?
- AutoTabsRouter.pageView sibling views defaults to path '' HOT 1
- Cannot navigate to child route with @PathParam.inherit("param"). HOT 6
- Issues Implementing Custom rebuildAll and popAllAndPushAll Methods in auto_route HOT 3
- deepLinkBuilder && doubling element's tree
- Pushing to sub-page in another tab and maintaining history? HOT 4
- deepLinkBuilder Not working on Production
- Default function argument value has no import prefix
- Automatically back when use CustomRoute with swipe for back
- Unable to Set Custom Transition Duration While Maintaining iOS Swipe Back Gesture
- browser buttons navigation in flutter web
- Got an error when navigation back web button with nested route HOT 1
- PopScope, Function(bool)? onPopInvoked, boolean value is always true for web even when canPop is false
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from auto_route_library.