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

Redirect to Original URL After Session Expiry and Re-login #6495

Merged
merged 16 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/Components/Auth/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,15 @@ export const Login = (props: { forgot?: boolean }) => {
window.location.pathname === "/" ||
window.location.pathname === "/login"
) {
window.location.href = "/facility";
const redirectParam = new URLSearchParams(window.location.search).get(
"redirect"
);
redirectParam
? (window.location.href = new URL(
redirectParam,
window.location.origin
).toString())
: (window.location.href = "/facility");
} else {
window.location.href = window.location.pathname.toString();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Redux/fireRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export const fireRequest = (
if (error.response.status > 400 && error.response.status < 500) {
if (error.response.data && error.response.data.detail) {
if (error.response.data.code === "token_not_valid") {
window.location.href = "/session-expired";
window.location.href = `/session-expired?redirect=${window.location.pathname}`;
}
Notification.Error({
msg: error.response.data.detail,
Expand Down
5 changes: 4 additions & 1 deletion src/Utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ export const handleSignOut = (forceReload: boolean) => {
Object.values(LocalStorageKeys).forEach((key) =>
localStorage.removeItem(key)
);
navigate("/");
const redirectURL = new URLSearchParams(window.location.search).get(
"redirect"
);
redirectURL ? navigate(`/?redirect=${redirectURL}`) : navigate("/");
if (forceReload) window.location.reload();
};

Expand Down
Loading