From ae19eaa76a09c779a51c72b46c4eb2ec21380d58 Mon Sep 17 00:00:00 2001 From: rahulkeswani101 Date: Thu, 1 Aug 2024 08:49:26 +0530 Subject: [PATCH] feat: redirect to original page after login (#5604) --- frontend/src/AppRoutes/Private.tsx | 3 +-- frontend/src/container/Login/index.tsx | 9 ++++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/frontend/src/AppRoutes/Private.tsx b/frontend/src/AppRoutes/Private.tsx index 669def6f44..43402fdbb2 100644 --- a/frontend/src/AppRoutes/Private.tsx +++ b/frontend/src/AppRoutes/Private.tsx @@ -76,9 +76,8 @@ function PrivateRoute({ children }: PrivateRouteProps): JSX.Element { isUserFetching: false, }, }); - if (!isLoggedIn) { - history.push(ROUTES.LOGIN); + history.push(ROUTES.LOGIN, { from: pathname }); } }; diff --git a/frontend/src/container/Login/index.tsx b/frontend/src/container/Login/index.tsx index df9a1c6a37..81a6c535a5 100644 --- a/frontend/src/container/Login/index.tsx +++ b/frontend/src/container/Login/index.tsx @@ -163,8 +163,15 @@ function Login({ response.payload.accessJwt, response.payload.refreshJwt, ); + if (history?.location?.state) { + const historyState = history?.location?.state as any; - history.push(ROUTES.APPLICATION); + if (historyState?.from) { + history.push(historyState?.from); + } else { + history.push(ROUTES.APPLICATION); + } + } } else { notifications.error({ message: response.error || t('unexpected_error'),