From 0cfaf254701e1092f541191f489ea9bbfa307e19 Mon Sep 17 00:00:00 2001 From: Soumik Sarker Date: Wed, 17 Dec 2025 22:44:17 +0600 Subject: [PATCH] Fixed browser history backlink for Following Navlink Signed-off-by: Soumik Sarker --- packages/webapp/components/ProtectedPage.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/webapp/components/ProtectedPage.tsx b/packages/webapp/components/ProtectedPage.tsx index e7b3b27797..2d77c1c587 100644 --- a/packages/webapp/components/ProtectedPage.tsx +++ b/packages/webapp/components/ProtectedPage.tsx @@ -2,6 +2,7 @@ import type { ReactElement, ReactNode } from 'react'; import React, { useContext, useEffect } from 'react'; import { useRouter } from 'next/router'; import AuthContext from '@dailydotdev/shared/src/contexts/AuthContext'; +import { AFTER_AUTH_PARAM } from '@dailydotdev/shared/src/components/auth/common'; export interface ProtectedPageProps { children: ReactNode; @@ -19,7 +20,12 @@ function ProtectedPage({ useEffect(() => { if (tokenRefreshed && !user) { - router.replace('/'); + const params = new URLSearchParams(window.location.search); + if (!params.get(AFTER_AUTH_PARAM)) { + params.set(AFTER_AUTH_PARAM, window.location.pathname); + } + const redirectUrl = params.toString() ? `/?${params.toString()}` : '/'; + router.replace(redirectUrl); } // @NOTE see https://dailydotdev.atlassian.net/l/cp/dK9h1zoM // eslint-disable-next-line react-hooks/exhaustive-deps