Skip to content

Commit

Permalink
ui: fix redirect to requested page after login
Browse files Browse the repository at this point in the history
if not logged user try to open some specific page it will be
redirected to it after login. eventually we had this in place
before, but it become not working due to bracking changes
in react router library.

Resolves: cockroachdb#67329

Release note(ui): fix redirect to originaly requested page after user login
  • Loading branch information
vladlos committed Jul 21, 2021
1 parent d6a4037 commit 63d780e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions pkg/ui/src/redux/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,13 @@ function shouldRedirect(location: Location) {
}

export function getLoginPage(location: Location) {
const query = !shouldRedirect(location) ? undefined : {
redirectTo: createPath({
const redirectTo = !shouldRedirect(location) ? undefined : createPath({
pathname: location.pathname,
search: location.search,
}),
};
});
return {
pathname: LOGIN_PAGE,
query: query,
search: `?redirectTo=${encodeURIComponent(redirectTo)}`,
};
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/ui/src/views/login/loginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class LoginPage extends React.Component<Props> {
const { location, history } = this.props;
const params = new URLSearchParams(location.search);
if (params.has("redirectTo")) {
history.push(params.get("redirectTo"));
history.push(decodeURIComponent(params.get("redirectTo")));
} else {
history.push("/");
}
Expand Down

0 comments on commit 63d780e

Please sign in to comment.