Skip to content

Conversation

@mflauti
Copy link
Collaborator

@mflauti mflauti commented Nov 11, 2025

Short description

This PR introduces error handling for the case when the user object returned from the token-exchange API fails schema validation.
Instead of silently redirect the user to the login page, we now display a dedicated page that informs the user about the validation failure. A new reusable ThankYouPage component has also been introduced following the design guidelines linked into the Jira issue.

How to test

  1. perform a normal login first, to retrieve a valid response object from the token-exchange API and use it to build a mock response for testing purpose
  2. mock the token-exchange response with netify, using the object obtained at the previous step. Modify one field inside the object to cause a validation failure (e.g. add some special chars to level field)
  3. open a new browser tab with netify enabled and attempt to log in again
    This way you should be redirected to the "User validation failed" page

@AndreaCimini90 AndreaCimini90 self-assigned this Nov 18, 2025
Copy link
Contributor

@AndreaCimini90 AndreaCimini90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to write the test case for this scenario.

Make the changes also for pg and pa

@@ -0,0 +1,46 @@
import * as React from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename the file and function with FeedbackPage.

Remember to write test

@@ -0,0 +1,26 @@
/* eslint-disable functional/immutable-data */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If userDataMatcher is used only in one place, we can avoid to create a new file and move the content into the file where we are using it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

userDataMatcher is used both in auth/reducers.ts and in auth/actions.ts

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right! Can you move this file under utility directory and rename it with user.utility.ts?

title={getLocalizedOrDefaultLabel(
'common',
'user-validation-failed.title',
'Validazione utente fallita'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the third parameter from the getLocalizedOrDefaultLabel

}

export function adaptedTokenExchangeError(originalError: any) {
// validazione `user` TokenExchangeRequest fallisce
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write this in english

isUnauthorizedUser: true,
response: {
...originalError.response,
status: 499,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

499 stands for?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a non-standard client-defined HTTP status code, so it's available for custom application-level error handling.

element={<AppNotAccessible onAssistanceClick={handleAssistanceClick} />}
element={<AppNotAccessible onAssistanceClick={handleGoToLandingSite} />}
/>
<Route
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can avoid to define another route and use the not_accessible one. Also in this case the app is not accessible. To distinguish between the two cases, you can pass a parameter (the error code can be enough) and do the logic inside the component.
In this way the UserValidationFailed component will be useless.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've refactored the code so that we now handle the two cases with two separate routes as before, both pointing to the same AppNotAccessible component (deleting UserValidationFailed) using a prop to distinguish them.

If you really meant using a single route for both cases I can update it and switch to a query-string parameter to discriminate between them. Just let me know which approach you prefer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the single route is the best approach

state.loading = false;
}
state.user = action.payload;
state.loading = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should restore the sessionStorage.setItem('user', JSON.stringify(user)); code removing it from the sessionGuard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants