-
Notifications
You must be signed in to change notification settings - Fork 706
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
Set current namespace when checking authz #1205
Set current namespace when checking authz #1205
Conversation
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 also works for me. So far I don't see any issue, let's see after testing it.
case LOCATION_CHANGE: | ||
const pathname = action.payload.location.pathname; | ||
// looks for /ns/:namespace in URL | ||
const matches = pathname.match(/\/ns\/([^/]*)/); | ||
if (matches) { | ||
return { ...state, current: matches[1] }; | ||
} | ||
case getType(actions.auth.setAuthenticated): |
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.
regarding your Typescript error. The problem is that LOCATION_CHANGE
doesn't have a break;
at the end of the case so this one is also executed after the previous one if it matches. That's why you are seeing the error, the payload
here can be a location change.
To fix it, either add a break
in the case LOCATION_CHANGE
or move this case above (but you also need to add a break;
)
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.
Excellent, thanks.
Great, thanks. QA'd locally and verified that:
|
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.
Cool, thanks for checking.
This diff is an alternative to #1201, which I think is caused by #1194. So instead, this PR reverts #1194 (well, most of it - there is one small change we want to keep) and provides an alternative.
So the issue mentioned on #1194 was that:
I think this meant that if you are not authenticated, we were setting the
current
namespace todefault
when the initialState was created for the reducer, and it was never overwritten from that point. The solution in #1194 was both to not set it in the initialState and add an action to update it when not set, but I think this is not the correct solution (and leads to the current issue mentioned in #1201).So this PR provides an alternative: that we explicitly set the current namespace when a user authenticates (
setAuthenticated
is only ever called at that one point). As mentioned on #1201, I don't think it should ever be empty and the only cases where we set it are:Let me know what you think.