From 68597d58d22532ba4ebe9c0f21b17a57b3ae909b Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Fri, 17 Jan 2025 18:45:57 +0600 Subject: [PATCH] feat: new user flag --- .../AuthenticationFlow/EmailLoginForm.tsx | 19 +++++++++++-------- .../AuthenticationFlow/GitHubButton.tsx | 7 +++++-- .../AuthenticationFlow/GoogleButton.tsx | 7 +++++-- .../AuthenticationFlow/LinkedInButton.tsx | 7 +++++-- .../TriggerVerifyAccount.tsx | 7 +++++-- 5 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/components/AuthenticationFlow/EmailLoginForm.tsx b/src/components/AuthenticationFlow/EmailLoginForm.tsx index ca99e837b..aa2bc9aa8 100644 --- a/src/components/AuthenticationFlow/EmailLoginForm.tsx +++ b/src/components/AuthenticationFlow/EmailLoginForm.tsx @@ -24,19 +24,22 @@ export function EmailLoginForm(props: EmailLoginFormProps) { setIsDisabled?.(true); setError(''); - const { response, error } = await httpPost<{ token: string }>( - `${import.meta.env.PUBLIC_API_URL}/v1-login`, - { - email, - password, - }, - ); + const { response, error } = await httpPost<{ + token: string; + isNewUser: boolean; + }>(`${import.meta.env.PUBLIC_API_URL}/v1-login`, { + email, + password, + }); // Log the user in and reload the page if (response?.token) { setAuthToken(response.token); - window.location.reload(); + const currentLocation = window.location.href; + const url = new URL(currentLocation, window.location.origin); + url.searchParams.set('isNewUser', String(response?.isNewUser || false)); + window.location.href = url.toString(); return; } diff --git a/src/components/AuthenticationFlow/GitHubButton.tsx b/src/components/AuthenticationFlow/GitHubButton.tsx index b0001699a..84ee56f78 100644 --- a/src/components/AuthenticationFlow/GitHubButton.tsx +++ b/src/components/AuthenticationFlow/GitHubButton.tsx @@ -32,7 +32,7 @@ export function GitHubButton(props: GitHubButtonProps) { setIsLoading(true); setIsDisabled?.(true); - httpGet<{ token: string }>( + httpGet<{ token: string; isNewUser: boolean }>( `${import.meta.env.PUBLIC_API_URL}/v1-github-callback${ window.location.search }`, @@ -74,7 +74,10 @@ export function GitHubButton(props: GitHubButtonProps) { localStorage.removeItem(GITHUB_REDIRECT_AT); localStorage.removeItem(GITHUB_LAST_PAGE); setAuthToken(response.token); - window.location.href = redirectUrl; + + const url = new URL(redirectUrl, window.location.origin); + url.searchParams.set('isNewUser', String(response?.isNewUser || false)); + window.location.href = url.toString(); }) .catch((err) => { setError('Something went wrong. Please try again later.'); diff --git a/src/components/AuthenticationFlow/GoogleButton.tsx b/src/components/AuthenticationFlow/GoogleButton.tsx index 950c2237d..dae9c4307 100644 --- a/src/components/AuthenticationFlow/GoogleButton.tsx +++ b/src/components/AuthenticationFlow/GoogleButton.tsx @@ -35,7 +35,7 @@ export function GoogleButton(props: GoogleButtonProps) { setIsLoading(true); setIsDisabled?.(true); - httpGet<{ token: string }>( + httpGet<{ token: string; isNewUser: boolean }>( `${import.meta.env.PUBLIC_API_URL}/v1-google-callback${ window.location.search }`, @@ -78,7 +78,10 @@ export function GoogleButton(props: GoogleButtonProps) { localStorage.removeItem(GOOGLE_REDIRECT_AT); localStorage.removeItem(GOOGLE_LAST_PAGE); setAuthToken(response.token); - window.location.href = redirectUrl; + + const url = new URL(redirectUrl, window.location.origin); + url.searchParams.set('isNewUser', String(response?.isNewUser || false)); + window.location.href = url.toString(); }) .catch((err) => { setError('Something went wrong. Please try again later.'); diff --git a/src/components/AuthenticationFlow/LinkedInButton.tsx b/src/components/AuthenticationFlow/LinkedInButton.tsx index 81924a068..028ca5cb8 100644 --- a/src/components/AuthenticationFlow/LinkedInButton.tsx +++ b/src/components/AuthenticationFlow/LinkedInButton.tsx @@ -32,7 +32,7 @@ export function LinkedInButton(props: LinkedInButtonProps) { setIsLoading(true); setIsDisabled?.(true); - httpGet<{ token: string }>( + httpGet<{ token: string; isNewUser: boolean }>( `${import.meta.env.PUBLIC_API_URL}/v1-linkedin-callback${ window.location.search }`, @@ -73,7 +73,10 @@ export function LinkedInButton(props: LinkedInButtonProps) { localStorage.removeItem(LINKEDIN_REDIRECT_AT); localStorage.removeItem(LINKEDIN_LAST_PAGE); setAuthToken(response.token); - window.location.href = redirectUrl; + + const url = new URL(redirectUrl, window.location.origin); + url.searchParams.set('isNewUser', String(response?.isNewUser || false)); + window.location.href = url.toString(); }) .catch((err) => { setError('Something went wrong. Please try again later.'); diff --git a/src/components/AuthenticationFlow/TriggerVerifyAccount.tsx b/src/components/AuthenticationFlow/TriggerVerifyAccount.tsx index 0978e38d1..4ef698719 100644 --- a/src/components/AuthenticationFlow/TriggerVerifyAccount.tsx +++ b/src/components/AuthenticationFlow/TriggerVerifyAccount.tsx @@ -13,7 +13,7 @@ export function TriggerVerifyAccount() { const triggerVerify = (code: string) => { setIsLoading(true); - httpPost<{ token: string }>( + httpPost<{ token: string; isNewUser: boolean }>( `${import.meta.env.PUBLIC_API_URL}/v1-verify-account`, { code, @@ -30,7 +30,10 @@ export function TriggerVerifyAccount() { triggerUtmRegistration(); setAuthToken(response.token); - window.location.href = '/'; + + const url = new URL('/', window.location.origin); + url.searchParams.set('isNewUser', String(response?.isNewUser || false)); + window.location.href = url.toString(); }) .catch((err) => { setIsLoading(false);