Skip to content

Commit 0bcaa26

Browse files
committed
refactor(authentication): simplify request code page navigation
- Remove isLinkingContext parameter from RequestCodePage - Update back navigation to use context.pop() consistently - Modify successful request navigation to use relative paths - Remove commented-out demo email suggestion code
1 parent 3b1595b commit 0bcaa26

File tree

1 file changed

+12
-56
lines changed

1 file changed

+12
-56
lines changed

lib/authentication/view/request_code_page.dart

Lines changed: 12 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,17 @@ import 'package:ui_kit/ui_kit.dart';
1818
/// {@endtemplate}
1919
class RequestCodePage extends StatelessWidget {
2020
/// {@macro request_code_page}
21-
const RequestCodePage({required this.isLinkingContext, super.key});
22-
23-
/// Whether this page is being shown in the account linking context.
24-
final bool isLinkingContext;
21+
const RequestCodePage({super.key});
2522

2623
@override
2724
Widget build(BuildContext context) {
2825
// AuthenticationBloc is assumed to be provided by a parent route.
29-
// Pass the linking context flag down to the view.
30-
return _RequestCodeView(isLinkingContext: isLinkingContext);
26+
return const _RequestCodeView();
3127
}
3228
}
3329

3430
class _RequestCodeView extends StatelessWidget {
35-
// Accept the flag from the parent page.
36-
const _RequestCodeView({required this.isLinkingContext});
37-
38-
final bool isLinkingContext;
31+
const _RequestCodeView();
3932

4033
@override
4134
Widget build(BuildContext context) {
@@ -51,19 +44,10 @@ class _RequestCodeView extends StatelessWidget {
5144
icon: const Icon(Icons.arrow_back),
5245
tooltip: MaterialLocalizations.of(context).backButtonTooltip,
5346
onPressed: () {
54-
// Navigate back differently based on the context.
55-
if (isLinkingContext) {
56-
// If linking, go back to Auth page preserving the linking query param.
57-
context.goNamed(
58-
Routes.authenticationName,
59-
queryParameters: isLinkingContext
60-
? {'context': 'linking'}
61-
: const {},
62-
);
63-
} else {
64-
// If normal sign-in, just go back to the Auth page.
65-
context.goNamed(Routes.authenticationName);
66-
}
47+
// Navigate back to the previous page in the stack.
48+
// GoRouter will handle the correct navigation based on the current
49+
// route's parent.
50+
context.pop();
6751
},
6852
),
6953
),
@@ -81,12 +65,11 @@ class _RequestCodeView extends StatelessWidget {
8165
);
8266
} else if (state.status ==
8367
AuthenticationStatus.requestCodeSuccess) {
84-
// Navigate to the code verification page on success, passing the email
85-
context.pushNamed(
86-
isLinkingContext
87-
? Routes.linkingVerifyCodeName
88-
: Routes.verifyCodeName,
89-
pathParameters: {'email': state.email!},
68+
// Navigate to the code verification page on success, passing the email.
69+
// The current route's parent will determine if this is for linking
70+
// or standard authentication.
71+
context.go(
72+
'${GoRouter.of(context).routerDelegate.currentConfiguration.last.matchedLocation}/${Routes.verifyCode}/${state.email!}',
9073
);
9174
}
9275
},
@@ -130,33 +113,6 @@ class _RequestCodeView extends StatelessWidget {
130113
),
131114
textAlign: TextAlign.center,
132115
),
133-
134-
// NOT NEEDED; any email is accepted in demo mode
135-
//
136-
//Display demo email suggestion if in demo environment
137-
// BlocSelector<AppBloc, AppState, AppEnvironment?>(
138-
// selector: (state) => state.environment,
139-
// builder: (context, environment) {
140-
// if (environment == AppEnvironment.demo) {
141-
// return Column(
142-
// children: [
143-
// const SizedBox(height: AppSpacing.md),
144-
// Text(
145-
// l10n.demoEmailSuggestionMessage(
146-
// 'admin@mail.com',
147-
// ),
148-
// style: textTheme.bodyMedium?.copyWith(
149-
// color: colorScheme.secondary,
150-
// fontWeight: FontWeight.bold,
151-
// ),
152-
// textAlign: TextAlign.center,
153-
// ),
154-
// ],
155-
// );
156-
// }
157-
// return const SizedBox.shrink();
158-
// },
159-
// ),
160116
const SizedBox(height: AppSpacing.xxl),
161117
_EmailLinkForm(isLoading: isLoading),
162118
],

0 commit comments

Comments
 (0)