Skip to content

Commit 0cfaf25

Browse files
Fixed browser history backlink for Following Navlink
Signed-off-by: Soumik Sarker <[email protected]>
1 parent 1805d62 commit 0cfaf25

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

packages/webapp/components/ProtectedPage.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { ReactElement, ReactNode } from 'react';
22
import React, { useContext, useEffect } from 'react';
33
import { useRouter } from 'next/router';
44
import AuthContext from '@dailydotdev/shared/src/contexts/AuthContext';
5+
import { AFTER_AUTH_PARAM } from '@dailydotdev/shared/src/components/auth/common';
56

67
export interface ProtectedPageProps {
78
children: ReactNode;
@@ -19,7 +20,12 @@ function ProtectedPage({
1920

2021
useEffect(() => {
2122
if (tokenRefreshed && !user) {
22-
router.replace('/');
23+
const params = new URLSearchParams(window.location.search);
24+
if (!params.get(AFTER_AUTH_PARAM)) {
25+
params.set(AFTER_AUTH_PARAM, window.location.pathname);
26+
}
27+
const redirectUrl = params.toString() ? `/?${params.toString()}` : '/';
28+
router.replace(redirectUrl);
2329
}
2430
// @NOTE see https://dailydotdev.atlassian.net/l/cp/dK9h1zoM
2531
// eslint-disable-next-line react-hooks/exhaustive-deps

0 commit comments

Comments
 (0)