@@ -66,7 +66,7 @@ export interface FiefAuthParameters {
6666 *
6767 * Defaults to `/login`.
6868 */
69- loginPath ?: string ;
69+ loginPath ?: string ;
7070
7171 /**
7272 * Absolute callback URI where the user
@@ -230,7 +230,6 @@ class FiefAuth {
230230 this . fiefAuthEdge = new FiefAuthServer (
231231 parameters . client ,
232232 async ( request ) => request . cookies . get ( parameters . sessionCookieName ) || null ,
233- parameters . userInfoCache ,
234233 ) ;
235234
236235 this . sessionCookieName = parameters . sessionCookieName ;
@@ -342,26 +341,25 @@ class FiefAuth {
342341 }
343342
344343 // Check authentication for configured paths
345- for ( let i = 0 ; i < compiledPathsAuthenticators . length ; i += 1 ) {
346- const { matcher, authenticate } = compiledPathsAuthenticators [ i ] ;
347- if ( matcher . exec ( request . nextUrl . pathname ) ) {
348- try {
349- // eslint-disable-next-line no-await-in-loop
350- await authenticate ( request ) ;
351- } catch ( err ) {
352- if ( err instanceof FiefAuthUnauthorized ) {
353- // eslint-disable-next-line no-await-in-loop
354- const authURL = await this . client . getAuthURL ( { redirectURI : this . redirectURI , scope : [ 'openid' ] } ) ;
355-
356- const response = NextResponse . redirect ( authURL ) ;
357- response . cookies . set ( this . returnToCookieName , request . nextUrl . pathname ) ;
358-
359- return response ;
360- }
361- if ( err instanceof FiefAuthForbidden ) {
362- return NextResponse . rewrite ( new URL ( this . forbiddenPath , request . url ) ) ;
363- }
344+ const matchingPath = compiledPathsAuthenticators . find (
345+ ( { matcher } ) => matcher . exec ( request . nextUrl . pathname ) ,
346+ ) ;
347+ if ( matchingPath ) {
348+ try {
349+ await matchingPath . authenticate ( request ) ;
350+ } catch ( err ) {
351+ if ( err instanceof FiefAuthUnauthorized ) {
352+ const authURL = await this . client . getAuthURL ( { redirectURI : this . redirectURI , scope : [ 'openid' ] } ) ;
353+
354+ const response = NextResponse . redirect ( authURL ) ;
355+ response . cookies . set ( this . returnToCookieName , request . nextUrl . pathname ) ;
356+
357+ return response ;
358+ }
359+ if ( err instanceof FiefAuthForbidden ) {
360+ return NextResponse . rewrite ( new URL ( this . forbiddenPath , request . url ) ) ;
364361 }
362+ throw err ;
365363 }
366364 }
367365
0 commit comments