@@ -284,33 +284,33 @@ export class RP {
284284
285285 public async getResponseRedirectUri ( mappings ?: Record < string , string > ) : Promise < string | undefined > {
286286 if ( ! mappings ) {
287- if ( ! this . _responseRedirectUri ) {
288- return undefined
289- }
290287 return this . _responseRedirectUri
291288 }
292289
293- let state : AuthorizationRequestState
294- const correlationId = mappings [ 'correlation_id' ] ?? mappings [ 'correlationId' ]
290+ // Attempt to retrieve state from session manager
291+ let state : AuthorizationRequestState | undefined
295292 if ( this . sessionManager ) {
293+ const correlationId = mappings [ 'correlation_id' ] ?? mappings [ 'correlationId' ]
294+
296295 if ( correlationId ) {
297296 state = await this . sessionManager . getRequestStateByCorrelationId ( correlationId , true )
298- } else {
299- const stateId = mappings [ 'state' ]
300- if ( stateId ) {
301- state = await this . sessionManager . getRequestStateByState ( stateId , true )
302- }
297+ } else if ( mappings [ 'state' ] ) {
298+ state = await this . sessionManager . getRequestStateByState ( mappings [ 'state' ] , true )
303299 }
304300 }
305301
306- let redirectUri : string | undefined
307- if ( state ) {
308- redirectUri = state . responseRedirectURI
309- }
302+ // Determine the redirect URI from state or fallback to default
303+ const redirectUri = state ?. responseRedirectURI ?? this . _responseRedirectUri
304+
310305 if ( ! redirectUri ) {
311- redirectUri = this . _responseRedirectUri
306+ return undefined
312307 }
313- return Object . entries ( mappings ) . reduce ( ( uri , [ key , value ] ) => uri . replace ( `:${ key } ` , value ) , redirectUri )
308+
309+ // Apply mappings to the redirect URI
310+ return Object . entries ( mappings ) . reduce (
311+ ( uri , [ key , value ] ) => uri . replace ( `:${ key } ` , value ) ,
312+ redirectUri
313+ )
314314 }
315315
316316 private newAuthorizationRequestOpts ( opts : {
0 commit comments