diff --git a/src/components/AuthenticationFlow/GitHubButton.tsx b/src/components/AuthenticationFlow/GitHubButton.tsx index 398a6e8f7..926b1993a 100644 --- a/src/components/AuthenticationFlow/GitHubButton.tsx +++ b/src/components/AuthenticationFlow/GitHubButton.tsx @@ -56,6 +56,12 @@ export function GitHubButton(props: GitHubButtonProps) { } } + const authRedirectUrl = localStorage.getItem('authRedirect'); + if (authRedirectUrl) { + localStorage.removeItem('authRedirect'); + redirectUrl = authRedirectUrl; + } + localStorage.removeItem(GITHUB_REDIRECT_AT); localStorage.removeItem(GITHUB_LAST_PAGE); Cookies.set(TOKEN_COOKIE_NAME, response.token, { diff --git a/src/components/AuthenticationFlow/GoogleButton.tsx b/src/components/AuthenticationFlow/GoogleButton.tsx index 1cd0d5714..e7e222a4b 100644 --- a/src/components/AuthenticationFlow/GoogleButton.tsx +++ b/src/components/AuthenticationFlow/GoogleButton.tsx @@ -55,6 +55,12 @@ export function GoogleButton(props: GoogleButtonProps) { } } + const authRedirectUrl = localStorage.getItem('authRedirect'); + if (authRedirectUrl) { + localStorage.removeItem('authRedirect'); + redirectUrl = authRedirectUrl; + } + localStorage.removeItem(GOOGLE_REDIRECT_AT); localStorage.removeItem(GOOGLE_LAST_PAGE); Cookies.set(TOKEN_COOKIE_NAME, response.token, { @@ -86,10 +92,11 @@ export function GoogleButton(props: GoogleButtonProps) { // For non authentication pages, we want to redirect back to the page // the user was on before they clicked the social login button if (!['/login', '/signup'].includes(window.location.pathname)) { - const pagePath = - ['/respond-invite', '/befriend'].includes(window.location.pathname) - ? window.location.pathname + window.location.search - : window.location.pathname; + const pagePath = ['/respond-invite', '/befriend'].includes( + window.location.pathname + ) + ? window.location.pathname + window.location.search + : window.location.pathname; localStorage.setItem(GOOGLE_REDIRECT_AT, Date.now().toString()); localStorage.setItem(GOOGLE_LAST_PAGE, pagePath); diff --git a/src/components/AuthenticationFlow/LinkedInButton.tsx b/src/components/AuthenticationFlow/LinkedInButton.tsx index 06764e01e..eb93b4517 100644 --- a/src/components/AuthenticationFlow/LinkedInButton.tsx +++ b/src/components/AuthenticationFlow/LinkedInButton.tsx @@ -55,6 +55,12 @@ export function LinkedInButton(props: LinkedInButtonProps) { } } + const authRedirectUrl = localStorage.getItem('authRedirect'); + if (authRedirectUrl) { + localStorage.removeItem('authRedirect'); + redirectUrl = authRedirectUrl; + } + localStorage.removeItem(LINKEDIN_REDIRECT_AT); localStorage.removeItem(LINKEDIN_LAST_PAGE); Cookies.set(TOKEN_COOKIE_NAME, response.token, { diff --git a/src/components/Authenticator/authenticator.ts b/src/components/Authenticator/authenticator.ts index fdc1c9ea7..2a8185abc 100644 --- a/src/components/Authenticator/authenticator.ts +++ b/src/components/Authenticator/authenticator.ts @@ -73,7 +73,10 @@ function handleAuthenticated() { // If the user is on a guest route, redirect them to the home page if (guestRoutes.includes(window.location.pathname)) { - window.location.href = '/'; + const authRedirect = window.localStorage.getItem('authRedirect') || '/'; + window.localStorage.removeItem('authRedirect'); + + window.location.href = authRedirect; } } diff --git a/src/components/TeamMarketing/TeamHeroBanner.tsx b/src/components/TeamMarketing/TeamHeroBanner.tsx index 885d2f2ad..21a1fa94b 100644 --- a/src/components/TeamMarketing/TeamHeroBanner.tsx +++ b/src/components/TeamMarketing/TeamHeroBanner.tsx @@ -1,4 +1,5 @@ import { CheckCircle, CheckCircle2, CheckIcon } from 'lucide-react'; +import { isLoggedIn } from '../../lib/jwt.ts'; const featureList = [ 'Create custom roadmaps for your team', @@ -8,12 +9,13 @@ const featureList = [ ]; export function TeamHeroBanner() { + const isAuthenticated = isLoggedIn(); return (
-

+

Roadmaps for Teams

@@ -31,26 +33,43 @@ export function TeamHeroBanner() {

{ + if (isAuthenticated) { + return; + } + + localStorage.setItem('authRedirect', '/team/new'); + }} + href={isAuthenticated ? '/team/new' : '/signup'} className="flex w-full items-center justify-center rounded-lg border border-transparent bg-purple-600 px-5 py-2 text-sm font-medium text-white hover:bg-blue-700 sm:w-auto sm:text-base" > Create your Team - - or   - - Login to your account - - - - Login to your account - + {!isAuthenticated && ( + <> + + or   + { + localStorage.setItem('authRedirect', '/team/new'); + }} + className="text-purple-600 underline hover:text-purple-700" + > + Login to your account + + + { + localStorage.setItem('authRedirect', '/team/new'); + }} + className="flex w-full items-center justify-center rounded-lg border border-purple-600 px-5 py-2 text-base text-sm font-medium text-purple-600 hover:bg-blue-700 sm:hidden sm:text-base" + > + Login to your account + + + )}
- +