Skip to content
Open
Changes from all 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
8 changes: 7 additions & 1 deletion packages/webapp/components/ProtectedPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down