@@ -101,18 +101,20 @@ interface DynamicClientRegistrationResponse extends OAuth2Client {
101101 registration_access_token ?: string ;
102102}
103103
104- // Cache for the dynamically registered client ID
105- let cachedClientId : string | null = null ;
104+ // Cache key for storing the dynamic client ID in session storage
105+ const DYNAMIC_CLIENT_ID_KEY = 'hydra-dynamic-client-id' ;
106106
107107async function getDynamicClientId ( ) : Promise < string > {
108108 // Only use dynamic registration for hydra provider
109109 if ( OAUTH_PROVIDER !== 'hydra' ) {
110110 return AUTH_CLIENT_ID ;
111111 }
112112
113- // Return cached client ID if available
114- if ( cachedClientId ) {
115- return cachedClientId ;
113+ // Check session storage for existing client ID
114+ const storedClientId = sessionStorage . getItem ( DYNAMIC_CLIENT_ID_KEY ) ;
115+ if ( storedClientId ) {
116+ console . log ( 'Using cached dynamic client ID from session storage:' , storedClientId ) ;
117+ return storedClientId ;
116118 }
117119
118120 // Use /oauth/hydra prefix which will be stripped by the proxy
@@ -155,8 +157,8 @@ async function getDynamicClientId(): Promise<string> {
155157 throw new Error ( 'No client_id returned from dynamic registration' ) ;
156158 }
157159
158- // Cache the client ID for future use
159- cachedClientId = data . client_id ;
160+ // Store the client ID in session storage for use across page loads
161+ sessionStorage . setItem ( DYNAMIC_CLIENT_ID_KEY , data . client_id ) ;
160162
161163 console . log ( 'Successfully registered dynamic OAuth2 client:' , data . client_id ) ;
162164 return data . client_id ;
0 commit comments