@@ -135,15 +135,24 @@ GoRouter createRouter({
135
135
appStatus == AppStatus .authenticated) {
136
136
print (' Redirect Decision: User is $appStatus .' );
137
137
138
- final isLinkingContext =
139
- state.uri.queryParameters['context' ] == 'linking' ;
138
+ final isLinkingContextQueryPresent = state.uri.queryParameters['context' ] == 'linking' ;
139
+ final isLinkingPathSegmentPresent = currentLocation.contains ('/linking/' );
140
+
141
+ // Determine if the current location is part of any linking flow (either via query or path segment)
142
+ final isAnyLinkingContext = isLinkingContextQueryPresent || isLinkingPathSegmentPresent;
140
143
141
144
// If an authenticated/anonymous user is on any authentication-related path:
142
145
if (currentLocation.startsWith (authenticationPath)) {
143
- // Allow navigation within auth paths if the linking context is active
144
- if (isLinkingContext) {
146
+ print (' Debug: Auth path detected. Current Location: $currentLocation ' );
147
+ print (' Debug: URI Query Parameters: ${state .uri .queryParameters }' );
148
+ print (' Debug: isLinkingContextQueryPresent: $isLinkingContextQueryPresent ' );
149
+ print (' Debug: isLinkingPathSegmentPresent: $isLinkingPathSegmentPresent ' );
150
+ print (' Debug: isAnyLinkingContext evaluated to: $isAnyLinkingContext ' );
151
+
152
+ // Allow navigation within auth paths if any linking context is active
153
+ if (isAnyLinkingContext) {
145
154
print (
146
- ' Action: $appStatus user on auth path ($currentLocation ) with linking context . Allowing navigation.' ,
155
+ ' Action: $appStatus user on auth linking path ($currentLocation ). Allowing navigation.' ,
147
156
);
148
157
return null ;
149
158
} else {
@@ -207,24 +216,41 @@ GoRouter createRouter({
207
216
);
208
217
},
209
218
routes: [
219
+ // Nested route for account linking flow (defined first for priority)
210
220
GoRoute (
211
- path: Routes .requestCode, // Use new path
212
- name: Routes .requestCodeName, // Use new name
213
- builder: (context, state) {
214
- // Extract the linking context flag from 'extra', default to false.
215
- final isLinking = (state.extra as bool ? ) ?? false ;
216
- return RequestCodePage (isLinkingContext: isLinking);
217
- },
221
+ path: Routes .accountLinking, // This is 'linking'
222
+ name: Routes .accountLinkingName, // Name for the linking segment
223
+ builder: (context, state) => const SizedBox .shrink (), // Placeholder
224
+ routes: [
225
+ GoRoute (
226
+ path: Routes .requestCode, // Path: /authentication/linking/request-code
227
+ name: Routes .linkingRequestCodeName,
228
+ builder: (context, state) =>
229
+ const RequestCodePage (isLinkingContext: true ),
230
+ ),
231
+ GoRoute (
232
+ path: '${Routes .verifyCode }/:email' , // Path: /authentication/linking/verify-code/:email
233
+ name: Routes .linkingVerifyCodeName,
234
+ builder: (context, state) {
235
+ final email = state.pathParameters['email' ]! ;
236
+ return EmailCodeVerificationPage (email: email);
237
+ },
238
+ ),
239
+ ],
240
+ ),
241
+ // Non-linking authentication routes (defined after linking routes)
242
+ GoRoute (
243
+ path: Routes .requestCode,
244
+ name: Routes .requestCodeName,
245
+ builder: (context, state) =>
246
+ const RequestCodePage (isLinkingContext: false ),
218
247
),
219
248
GoRoute (
220
- path:
221
- '${Routes .verifyCode }/:email' , // Use new path with email parameter
222
- name: Routes .verifyCodeName, // Use new name
249
+ path: '${Routes .verifyCode }/:email' ,
250
+ name: Routes .verifyCodeName,
223
251
builder: (context, state) {
224
- final email = state.pathParameters['email' ]! ; // Extract email
225
- return EmailCodeVerificationPage (
226
- email: email,
227
- ); // Use renamed page
252
+ final email = state.pathParameters['email' ]! ;
253
+ return EmailCodeVerificationPage (email: email);
228
254
},
229
255
),
230
256
],
0 commit comments