-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
M2-6175: Allow hotlinking to activity
- Loading branch information
1 parent
7ebf2ae
commit 5476d61
Showing
9 changed files
with
40 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { useEffect } from 'react'; | ||
|
||
import { useLocation, useNavigate } from 'react-router-dom'; | ||
|
||
import { ROUTES } from '~/shared/constants'; | ||
|
||
interface LoginWithRedirectProps { | ||
/** | ||
* Where to go after the user logs in. Defaults to the current URL | ||
*/ | ||
redirectTo?: string; | ||
} | ||
|
||
/** | ||
* An empty component that automatically redirects to the login page if the user is not authenticated. Pass | ||
* the redirect state to specify where to go after the user logs in. | ||
*/ | ||
export const LoginWithRedirect = ({ redirectTo }: LoginWithRedirectProps) => { | ||
const navigate = useNavigate(); | ||
const location = useLocation(); | ||
useEffect(() => { | ||
const backRedirectPath = redirectTo || `${location.pathname}${location.search}`; | ||
navigate(ROUTES.login.path, { state: { backRedirectPath } }); | ||
}, [navigate, redirectTo]); | ||
|
||
return null; | ||
}; |