-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'next' into v2-layouts-cont
- Loading branch information
Showing
33 changed files
with
389 additions
and
225 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
11 changes: 10 additions & 1 deletion
11
apps/web/src/components/layout/components/EnsureOnboardingComplete.tsx
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 |
---|---|---|
@@ -1,16 +1,25 @@ | ||
import { Navigate, useLocation } from 'react-router-dom'; | ||
import { useAuth } from '../../../hooks/useAuth'; | ||
import { ROUTES } from '../../../constants/routes'; | ||
import { useBlueprint } from '../../../hooks/index'; | ||
import { useBlueprint, useRedirectURL } from '../../../hooks'; | ||
|
||
export function EnsureOnboardingComplete({ children }: any) { | ||
useBlueprint(); | ||
const location = useLocation(); | ||
const { getRedirectURL } = useRedirectURL(); | ||
const { currentOrganization, environmentId } = useAuth(); | ||
|
||
if ((!currentOrganization || !environmentId) && location.pathname !== ROUTES.AUTH_APPLICATION) { | ||
return <Navigate to={ROUTES.AUTH_APPLICATION} replace />; | ||
} | ||
|
||
const redirectURL = getRedirectURL(); | ||
if (redirectURL) { | ||
// Note: Do not use react-router-dom. The version we have doesn't do instant cross origin redirects. | ||
window.location.replace(redirectURL); | ||
|
||
return null; | ||
} | ||
|
||
return children; | ||
} |
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,48 @@ | ||
import { useCallback } from 'react'; | ||
import { createCookieHandler } from '../utils/cookies'; | ||
import { assertProtocol } from '../utils/url'; | ||
|
||
const novuRedirectURLCookie = createCookieHandler('nv_redirect_url'); | ||
|
||
const REDIRECT_URL_SEARCH_PARAM = 'redirect_url'; | ||
|
||
const REDIRECT_COOKIE_EXPIRY_DAYS = 7; | ||
|
||
export function useRedirectURL() { | ||
const setRedirectURL = useCallback(() => { | ||
const redirectURLFromParams = new URL(window.location.href).searchParams.get(REDIRECT_URL_SEARCH_PARAM) || ''; | ||
|
||
// If there is a redirect URL in the URL, set it in the cookie. | ||
if (redirectURLFromParams) { | ||
// Protect against XSS attacks via the javascript: pseudo protocol. | ||
assertProtocol(redirectURLFromParams); | ||
// Expires in 7 days. | ||
novuRedirectURLCookie.set(redirectURLFromParams, { expires: REDIRECT_COOKIE_EXPIRY_DAYS }); | ||
|
||
// Clean the URL so that the redirect URL doesn't get used again. | ||
const url = new URL(window.location.href); | ||
url.searchParams.delete(REDIRECT_URL_SEARCH_PARAM); | ||
history.replaceState({}, '', url.href); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
const getRedirectURL = useCallback(() => { | ||
const redirectURLFromCookie = novuRedirectURLCookie.get(); | ||
|
||
// If there is a cookie in the URL, redirect to that URL. Otherwise, its a noop. | ||
if (redirectURLFromCookie) { | ||
// Clean the cookie first, so that it doesn't get used again. | ||
novuRedirectURLCookie.remove(); | ||
|
||
return redirectURLFromCookie; | ||
} | ||
|
||
return ''; | ||
}, []); | ||
|
||
return { | ||
setRedirectURL, | ||
getRedirectURL, | ||
}; | ||
} |
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
Oops, something went wrong.