Skip to content

Commit 1b709b2

Browse files
committed
refactor(router): improve route permission checking and error handling
- Enhance the process of converting allowed route names to their base paths - Add an assertion to catch configuration errors when a route name is not defined in topLevelPaths - Maintain the functionality of filtering out null values
1 parent 9919096 commit 1b709b2

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lib/router/router.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,17 @@ GoRouter createRouter({
107107

108108
// Convert the allowed route names into a list of their base paths.
109109
final authorizedPaths = allowedRouteNames
110-
.map((name) => topLevelPaths[name])
111-
.whereType<
112-
String
113-
>() // Filter out any nulls if a name is not in the map.
110+
.map((name) {
111+
final path = topLevelPaths[name];
112+
assert(
113+
path != null,
114+
'Configuration error: Route name "$name" from routePermissions is not defined in topLevelPaths.',
115+
);
116+
return path;
117+
})
118+
.whereType<String>()
114119
.toList();
115-
120+
116121
// Check if the destination path starts with any of the authorized base
117122
// paths, or if it's the universally accessible settings page.
118123
final isAuthorized =

0 commit comments

Comments
 (0)