@@ -164,35 +164,43 @@ export abstract class RecipeRouter {
164164 routePath === path ||
165165 new RegExp ( "^" + routePath . replace ( / : \w + / g, "[^/]+" ) . replace ( / \/ \* / g, "/[^/]+" ) + "$" ) . test ( path )
166166 ) {
167- components = components . concat ( routeComps ) ;
167+ components = components . concat (
168+ routeComps . map ( ( c ) => {
169+ return { comp : c , route : routePath } ;
170+ } )
171+ ) ;
168172 }
169173 }
170174 return components ;
171- } , [ ] as ComponentWithRecipeAndMatchingMethod [ ] ) ;
175+ } , [ ] as { comp : ComponentWithRecipeAndMatchingMethod ; route : string } [ ] ) ;
172176
173177 // 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 ( ) ) ;
175179
176180 // We default to to one requested by id or the first in the list
177181 // 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 ;
179183 if ( routeComponents . length === 0 ) {
180184 defaultComp = undefined ;
181185 } else if ( componentMatchingRid !== undefined ) {
182- defaultComp = componentMatchingRid ;
186+ defaultComp = componentMatchingRid . comp ;
183187 } else {
184- defaultComp = routeComponents [ 0 ] ;
188+ defaultComp = routeComponents [ 0 ] . comp ;
185189 }
186190
187191 // We check if any non-auth recipe (emailverification, totp) can handle this
188192 // There should be no overlap between the routes handled by those and the auth recipes
189193 // 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+ } ) ;
193201
194202 if ( matchingNonAuthComponent ) {
195- return matchingNonAuthComponent ;
203+ return matchingNonAuthComponent . comp ;
196204 }
197205
198206 // We use this option in `canHandleRoute`, because it may be called by custom UIs before
@@ -205,14 +213,17 @@ export abstract class RecipeRouter {
205213 if ( SuperTokens . usesDynamicLoginMethods === false ) {
206214 // If we are not using dynamic login methods, we can use the rid requested by the app
207215 if ( componentMatchingRid ) {
208- return componentMatchingRid ;
216+ return componentMatchingRid . comp ;
209217 }
210218
211219 // if we have a static firstFactors config we take it into account on the auth page
212220 // Other pages shouldn't care about this configuration.
213221 // Embedded components are not affected, since this is only called by the routing component.
214222 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+ ) ;
216227 } else {
217228 return defaultComp ;
218229 }
@@ -227,21 +238,24 @@ export abstract class RecipeRouter {
227238 // If we are using dynamic login methods, we check that the requested rid belongs to an enabled recipe
228239 if (
229240 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
231242 priorityOrder . some (
232243 ( a ) =>
233- a . rid === componentMatchingRid . recipeID &&
244+ a . rid === componentMatchingRid . comp . recipeID &&
234245 a . factorsProvided . some ( ( factorId ) => dynamicLoginMethods . firstFactors . includes ( factorId ) )
235246 ) ) // or an enabled auth recipe
236247 ) {
237- return componentMatchingRid ;
248+ return componentMatchingRid . comp ;
238249 }
239250
240251 // if we have a firstFactors config for the tenant we take it into account on the auth page
241252 // Other pages shouldn't care about this configuration.
242253 // Embedded components are not affected, since this is only called by the routing component.
243254 if ( isAuthPage ) {
244- return chooseComponentBasedOnFirstFactors ( dynamicLoginMethods . firstFactors , routeComponents ) ;
255+ return chooseComponentBasedOnFirstFactors (
256+ dynamicLoginMethods . firstFactors ,
257+ routeComponents . map ( ( c ) => c . comp )
258+ ) ;
245259 }
246260
247261 return undefined ;
0 commit comments