-
Notifications
You must be signed in to change notification settings - Fork 4
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
Homepage accessible regardless of login status #1049 #1050
Homepage accessible regardless of login status #1049 #1050
Conversation
…n not logged in #1049 The user's login state now has no effect on access to the homepage or display of the navigation drawer. This means that DLS now allows access to the homepage at the web root and the navigation drawer shows all web app routes (access to these is determined elsewhere). This is in comparison to how things used to work on DLS, whereby all nav drawer routes including the homepage were inaccessible until the user logged in.
Since this PR is related to SciGateway login changes, I thought I'd lump in this additional fix. This addresses the problem whereby the user would try to navigate to a protected resource, be redirected to login, login successfully and then be mistakenly directed to the homepage instead of their original page. This was previously working by storing the referrer in the login redirect state but this state is cleared on a page refresh, meaning we defaulted back to the homepage. We now store the referrer in localStorage and clear it when we don't need it.
Codecov Report
@@ Coverage Diff @@
## develop #1050 +/- ##
===========================================
- Coverage 97.94% 97.94% -0.01%
===========================================
Files 42 42
Lines 1557 1555 -2
Branches 411 421 +10
===========================================
- Hits 1525 1523 -2
Misses 31 31
Partials 1 1
Continue to review full report at Codecov.
|
dispatch(authorised()); | ||
|
||
// redirect the user to the original page they were trying to get to | ||
// the referrer is added by the redirect in routing.component.tsx | ||
const previousRouteState = getState().router.location.state; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if you moved the reading of previousRouteState
before dispatching the authorised()
action then the router referrer would be accurate. The redirect to /logout
happens because if a user tries to access the login page when logged in they should instead see the logout page. If you grab what's in the referrer before the user is logged in, then this should be before the redirect to /logout
.
Though tbh, I don't mind doing it via localStorage, just thought you'd want to know what was causing the problem :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I think I get it. I'll give it another go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works well - on page load you see the homepage, and upon clicking any of the links on the homepage or in the sidebar you are redirected to the login page and once you login you are taken back to the link you clicked on and the sidebar opens as a default.
I'll wait to see if you manage to get the old redirect working though
The reason the referrer was being wiped from state was because the user was logging in, which meant the login page becomes inaccessible and is thus replaced with logout. This removes the referrer from state. I am now changing this so we grab the referrer earlier in the process before redirecting. This removes the need to use localStorage
@louise-davies fixed with your solution! You were right, I simply needed to grab the referrer from state a little earlier. Thanks for the help |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works well with the new fix - glad I could help out and that it worked :)
Description
The user's login state now has no effect on access to the homepage or display of the navigation drawer. This means that, like ISIS, DLS now allows access to the homepage at the web root and the navigation drawer shows all web app routes (but no access allowed while not logged in). This is in comparison to how things used to work on DLS, whereby all nav drawer routes including the homepage were inaccessible until the user logged in.
This PR also includes a fix to a problem where the user would not be redirected to their original request following a successful login, instead being redirected to the homepage. This took a lot of trial and error but I came to the conclusion that this was because the current method detailed below no longer works:
/protected/domain
/protected/domain
in router state/logout
, clearing the router state in the process (still not sure why this location change happens)The state is cleared between page refreshes/redirects because this is what
react-router-dom
does. But I'm unsure as to why a routerREPLACE
to/logout
happens.To get around this, I made a new method whereby the referral URL is stored in
localStorage
instead. It is then fetched, changed and deleted as required.Testing instructions
Run this with at least one other plugin loaded so that the navigation drawer can be populated. Set the
"authUrl"
in settings.json to be"https://datagateway-preprod.diamond.ac.uk/api"
to mimic DLS DG environment (no auto login).When navigating to the web root, you should be directed to the homepage instead of
/login
. Also, the navigation bar should be accessible but you should be redirected to/login
upon trying to navigate to any of the routes.Agile board tracking
Closes #1049