@@ -164,35 +164,43 @@ export abstract class RecipeRouter {
164
164
routePath === path ||
165
165
new RegExp ( "^" + routePath . replace ( / : \w + / g, "[^/]+" ) . replace ( / \/ \* / g, "/[^/]+" ) + "$" ) . test ( path )
166
166
) {
167
- components = components . concat ( routeComps ) ;
167
+ components = components . concat (
168
+ routeComps . map ( ( c ) => {
169
+ return { comp : c , route : routePath } ;
170
+ } )
171
+ ) ;
168
172
}
169
173
}
170
174
return components ;
171
- } , [ ] as ComponentWithRecipeAndMatchingMethod [ ] ) ;
175
+ } , [ ] as { comp : ComponentWithRecipeAndMatchingMethod ; route : string } [ ] ) ;
172
176
173
177
// We check the query params to see if any recipe was requested by id
174
- const componentMatchingRid = routeComponents . find ( ( c ) => c . matches ( ) ) ;
178
+ const componentMatchingRid = routeComponents . find ( ( c ) => c . comp . matches ( ) ) ;
175
179
176
180
// We default to to one requested by id or the first in the list
177
181
// i.e.: the first prebuilt ui in the list the user provided that can handle this route.
178
- let defaultComp ;
182
+ let defaultComp : ComponentWithRecipeAndMatchingMethod | undefined ;
179
183
if ( routeComponents . length === 0 ) {
180
184
defaultComp = undefined ;
181
185
} else if ( componentMatchingRid !== undefined ) {
182
- defaultComp = componentMatchingRid ;
186
+ defaultComp = componentMatchingRid . comp ;
183
187
} else {
184
- defaultComp = routeComponents [ 0 ] ;
188
+ defaultComp = routeComponents [ 0 ] . comp ;
185
189
}
186
190
187
191
// We check if any non-auth recipe (emailverification, totp) can handle this
188
192
// There should be no overlap between the routes handled by those and the auth recipes
189
193
// so if there is a match we can return early
190
- const matchingNonAuthComponent = routeComponents . find (
191
- ( comp ) => ! priorityOrder . map ( ( a ) => a . rid ) . includes ( comp . recipeID )
192
- ) ;
194
+ const matchingNonAuthComponent = routeComponents . find ( ( comp ) => {
195
+ const ridlist = priorityOrder . map ( ( a ) => a . rid ) ;
196
+ return (
197
+ ! ridlist . includes ( comp . comp . recipeID ) ||
198
+ comp . route !== SuperTokens . getInstanceOrThrow ( ) . appInfo . websiteBasePath . getAsStringDangerous ( )
199
+ ) ;
200
+ } ) ;
193
201
194
202
if ( matchingNonAuthComponent ) {
195
- return matchingNonAuthComponent ;
203
+ return matchingNonAuthComponent . comp ;
196
204
}
197
205
198
206
// We use this option in `canHandleRoute`, because it may be called by custom UIs before
@@ -205,14 +213,17 @@ export abstract class RecipeRouter {
205
213
if ( SuperTokens . usesDynamicLoginMethods === false ) {
206
214
// If we are not using dynamic login methods, we can use the rid requested by the app
207
215
if ( componentMatchingRid ) {
208
- return componentMatchingRid ;
216
+ return componentMatchingRid . comp ;
209
217
}
210
218
211
219
// if we have a static firstFactors config we take it into account on the auth page
212
220
// Other pages shouldn't care about this configuration.
213
221
// Embedded components are not affected, since this is only called by the routing component.
214
222
if ( isAuthPage && mfaRecipe && mfaRecipe . config . firstFactors !== undefined ) {
215
- return chooseComponentBasedOnFirstFactors ( mfaRecipe . config . firstFactors , routeComponents ) ;
223
+ return chooseComponentBasedOnFirstFactors (
224
+ mfaRecipe . config . firstFactors ,
225
+ routeComponents . map ( ( c ) => c . comp )
226
+ ) ;
216
227
} else {
217
228
return defaultComp ;
218
229
}
@@ -227,21 +238,24 @@ export abstract class RecipeRouter {
227
238
// If we are using dynamic login methods, we check that the requested rid belongs to an enabled recipe
228
239
if (
229
240
componentMatchingRid && // if we find a component matching by rid
230
- ( ! priorityOrder . map ( ( a ) => a . rid ) . includes ( componentMatchingRid . recipeID ) || // from a non-auth recipe
241
+ ( ! priorityOrder . map ( ( a ) => a . rid ) . includes ( componentMatchingRid . comp . recipeID ) || // from a non-auth recipe
231
242
priorityOrder . some (
232
243
( a ) =>
233
- a . rid === componentMatchingRid . recipeID &&
244
+ a . rid === componentMatchingRid . comp . recipeID &&
234
245
a . factorsProvided . some ( ( factorId ) => dynamicLoginMethods . firstFactors . includes ( factorId ) )
235
246
) ) // or an enabled auth recipe
236
247
) {
237
- return componentMatchingRid ;
248
+ return componentMatchingRid . comp ;
238
249
}
239
250
240
251
// if we have a firstFactors config for the tenant we take it into account on the auth page
241
252
// Other pages shouldn't care about this configuration.
242
253
// Embedded components are not affected, since this is only called by the routing component.
243
254
if ( isAuthPage ) {
244
- return chooseComponentBasedOnFirstFactors ( dynamicLoginMethods . firstFactors , routeComponents ) ;
255
+ return chooseComponentBasedOnFirstFactors (
256
+ dynamicLoginMethods . firstFactors ,
257
+ routeComponents . map ( ( c ) => c . comp )
258
+ ) ;
245
259
}
246
260
247
261
return undefined ;
0 commit comments