Skip to content

Commit

Permalink
Merge pull request deriv-com#169 from ahmed-deriv/ahmed/DSEC-57013/fi…
Browse files Browse the repository at this point in the history
…x--open-redirect-get-paramter

ahmed/DSEC-57013/fix--open-redirect-get-paramter
  • Loading branch information
sandeep-deriv authored Nov 13, 2024
2 parents 03fd940 + c5f74be commit d65c30f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/pages/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import Layout from '@theme/Layout';
import { Login } from '../features/Login/Login';
import useAuthParams from '../hooks/useAuthParams';
import { useEffect } from 'react';
import { useLocation } from '@docusaurus/router';
import { Redirect, useLocation } from '@docusaurus/router';
import useAuthContext from '../hooks/useAuthContext';

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

useEffect(() => {
checkUrlParams(search);
Expand All @@ -18,11 +19,15 @@ export default function Auth(): JSX.Element {
useEffect(() => {
if (is_logged_in) {
const params = new URLSearchParams(search);
const redirect_route = params.get('route')?.replace(/%2F/g, '/') || '/';
window.location.assign(window.location.origin + redirect_route);
const redirect_route = params.get('route')?.replace(/%2F/g, '/') || '/';
setRedirectRoute(redirect_route);
}
}, [is_logged_in, search]);

if (redirect_route) {
return <Redirect to={redirect_route} />;
}

return (
<Layout title='Auth' description='Deriv API documentation'>
<main>
Expand Down

0 comments on commit d65c30f

Please sign in to comment.