Skip to content

Commit 06acb9a

Browse files
committed
refactor(router): Improve auth path redirection
- Redirect authenticated users from auth paths - Clarify anonymous user redirection logic
1 parent d957621 commit 06acb9a

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lib/router/router.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,24 @@ GoRouter createRouter({
149149
print(' Debug: isLinkingPathSegmentPresent: $isLinkingPathSegmentPresent');
150150
print(' Debug: isAnyLinkingContext evaluated to: $isAnyLinkingContext');
151151

152-
// Allow navigation within auth paths if any linking context is active
152+
// If the user is authenticated, always redirect away from auth paths.
153+
if (appStatus == AppStatus.authenticated) {
154+
print(
155+
' Action: Authenticated user on auth path ($currentLocation). Redirecting to $feedPath',
156+
);
157+
return feedPath;
158+
}
159+
160+
// If the user is anonymous, allow navigation within auth paths if in a linking context.
161+
// Otherwise, redirect anonymous users trying to access non-linking auth paths to feed.
153162
if (isAnyLinkingContext) {
154163
print(
155-
' Action: $appStatus user on auth linking path ($currentLocation). Allowing navigation.',
164+
' Action: Anonymous user on auth linking path ($currentLocation). Allowing navigation.',
156165
);
157166
return null;
158167
} else {
159-
// Redirect to feed if not in a linking context (e.g., user manually types /authentication)
160168
print(
161-
' Action: $appStatus user trying to access an auth path ($currentLocation) without linking context. Redirecting to $feedPath',
169+
' Action: Anonymous user trying to access non-linking auth path ($currentLocation). Redirecting to $feedPath',
162170
);
163171
return feedPath;
164172
}

0 commit comments

Comments
 (0)