Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix user redirects and tests #646

Merged
merged 7 commits into from
Jan 18, 2024
Merged

Fix user redirects and tests #646

merged 7 commits into from
Jan 18, 2024

Conversation

erikguntner
Copy link
Collaborator

@erikguntner erikguntner commented Jan 17, 2024

Closes #645

What changes did you make?

  • Removed the resetting of credentials on logout
  • Updated the redirect when visiting protected outs from / to /signin
  • Removed the /profile path from the protected paths in the e2e tests since it no longer exists
  • Made /signout a protected route. I noticed it wasn't protected and therefore wasn't causing a token refresh if they were expired.

Rationale behind the changes?

I made these changes to correctly redirect the user based on 2 cases:

  1. When the user logs out they are redirected to /
  2. When the user tries to access a protected page. For example, when they aren’t logged in or logged in as a different user role they are redirected to the /signin in page

One issue I ran into was the ProtectedRoute component was redirecting the user after logging out instead of allowing us to choose the path. This was being caused by this line of code in app/src/components/common/AuthenticatedHeader.tsx:

appDispatch(setCredentials({user: null, token: null}))

The ProtectedRoute component relies on the user object to determine whether to navigate the user to /signin or render the necessary components. A change to the user object was causing the component to render<Navigate to="/signin" state={{from: location}} replace />; and override our call to navigate('/'). By removing the state update we can now redirect the user to the home page. However, the user object is still stored in state, but since the credentials are no longer valid the user can't log in or access any protected routes. The user object will also be reset anytime the user revisits the application or a protected endpoint.

Testing done for these changes

  • Updated Cypress tests to reflect the proper route redirects. There were also a lot of linter updates that were updated as well.

Screenshots of Proposed Changes Of The Website (if any, please do not screen shot code changes)

Visuals before changes are applied

image

Visuals after changes are applied
Screen.Recording.2024-01-17.at.12.58.00.PM.mov

Copy link
Member

@JpadillaCoding JpadillaCoding left a comment

Choose a reason for hiding this comment

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

The intended changes of redirecting the user on logout to / works and the user is also redirected to /signin when they are not logged in and try to access a protected route.

Thanks for the fix Erik!

@erikguntner erikguntner merged commit 672464a into main Jan 18, 2024
4 checks passed
@Joshua-Douglas Joshua-Douglas deleted the fix-redirects branch February 6, 2024 03:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update user redirects and tests
2 participants