@@ -1290,6 +1290,15 @@ export class Clerk implements ClerkInterface {
1290
1290
eventBus . emit ( events . TokenUpdate , { token : null } ) ;
1291
1291
}
1292
1292
1293
+ /**
1294
+ * Invalidate previously cache pages with auth state before navigating
1295
+ */
1296
+ const onBeforeSetActive : SetActiveHook =
1297
+ typeof window !== 'undefined' && typeof window . __unstable__onBeforeSetActive === 'function'
1298
+ ? window . __unstable__onBeforeSetActive
1299
+ : noop ;
1300
+ await onBeforeSetActive ( ) ;
1301
+
1293
1302
// Only triggers navigation for internal AIO components routing or multi-session switch, in order to not affect custom flows
1294
1303
const isSwitchingSessions = this . session ?. id != session . id ;
1295
1304
const shouldNavigateOnSetActive = this . #componentNavigationContext || isSwitchingSessions ;
@@ -1301,9 +1310,19 @@ export class Clerk implements ClerkInterface {
1301
1310
componentNavigationContext : this . #componentNavigationContext,
1302
1311
} ) ;
1303
1312
}
1304
-
1305
1313
this . #setAccessors( session ) ;
1306
1314
this . #emit( ) ;
1315
+
1316
+ /**
1317
+ * Invoke the Next.js middleware to synchronize server and client state after resolving a session task.
1318
+ * This ensures that any server-side logic depending on the session status (like middleware-based
1319
+ * redirects or protected routes) correctly reflects the updated client authentication state.
1320
+ */
1321
+ const onAfterSetActive : SetActiveHook =
1322
+ typeof window !== 'undefined' && typeof window . __unstable__onAfterSetActive === 'function'
1323
+ ? window . __unstable__onAfterSetActive
1324
+ : noop ;
1325
+ await onAfterSetActive ( ) ;
1307
1326
} ;
1308
1327
1309
1328
public __experimental_navigateToTask = async ( { redirectUrlComplete } : NextTaskParams = { } ) : Promise < void > => {
0 commit comments