Skip to content

Commit d65c30f

Browse files
Merge pull request #169 from ahmed-deriv/ahmed/DSEC-57013/fix--open-redirect-get-paramter
ahmed/DSEC-57013/fix--open-redirect-get-paramter
2 parents 03fd940 + c5f74be commit d65c30f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/pages/auth.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ import Layout from '@theme/Layout';
33
import { Login } from '../features/Login/Login';
44
import useAuthParams from '../hooks/useAuthParams';
55
import { useEffect } from 'react';
6-
import { useLocation } from '@docusaurus/router';
6+
import { Redirect, useLocation } from '@docusaurus/router';
77
import useAuthContext from '../hooks/useAuthContext';
88

99
export default function Auth(): JSX.Element {
1010
const { search } = useLocation(); // to get the search params
1111
const { is_logged_in } = useAuthContext();
1212
const { checkUrlParams } = useAuthParams();
13+
const [redirect_route, setRedirectRoute] = React.useState<string | null>(null);
1314

1415
useEffect(() => {
1516
checkUrlParams(search);
@@ -18,11 +19,15 @@ export default function Auth(): JSX.Element {
1819
useEffect(() => {
1920
if (is_logged_in) {
2021
const params = new URLSearchParams(search);
21-
const redirect_route = params.get('route')?.replace(/%2F/g, '/') || '/';
22-
window.location.assign(window.location.origin + redirect_route);
22+
const redirect_route = params.get('route')?.replace(/%2F/g, '/') || '/';
23+
setRedirectRoute(redirect_route);
2324
}
2425
}, [is_logged_in, search]);
2526

27+
if (redirect_route) {
28+
return <Redirect to={redirect_route} />;
29+
}
30+
2631
return (
2732
<Layout title='Auth' description='Deriv API documentation'>
2833
<main>

0 commit comments

Comments
 (0)