From 83e315aef755067366362e6f8e2f726431a1d0c5 Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Mon, 3 Feb 2025 17:06:22 +0600 Subject: [PATCH] feat: add first login flag (#8161) --- .../AuthenticationFlow/EmailLoginForm.tsx | 4 +--- src/components/AuthenticationFlow/GitHubButton.tsx | 7 ++++--- src/components/AuthenticationFlow/GoogleButton.tsx | 7 ++++--- .../AuthenticationFlow/LinkedInButton.tsx | 7 ++++--- .../AuthenticationFlow/TriggerVerifyAccount.tsx | 13 +++++++++---- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/components/AuthenticationFlow/EmailLoginForm.tsx b/src/components/AuthenticationFlow/EmailLoginForm.tsx index 2907433fb..dd3c3c124 100644 --- a/src/components/AuthenticationFlow/EmailLoginForm.tsx +++ b/src/components/AuthenticationFlow/EmailLoginForm.tsx @@ -38,9 +38,7 @@ export function EmailLoginForm(props: EmailLoginFormProps) { const currentLocation = window.location.href; const url = new URL(currentLocation, window.location.origin); - if (response?.isNewUser) { - url.searchParams.set(FIRST_LOGIN_PARAM, '1'); - } + url.searchParams.set(FIRST_LOGIN_PARAM, response?.isNewUser ? '1' : '0'); window.location.href = url.toString(); return; } diff --git a/src/components/AuthenticationFlow/GitHubButton.tsx b/src/components/AuthenticationFlow/GitHubButton.tsx index 5ea5017e2..3e6681730 100644 --- a/src/components/AuthenticationFlow/GitHubButton.tsx +++ b/src/components/AuthenticationFlow/GitHubButton.tsx @@ -81,9 +81,10 @@ export function GitHubButton(props: GitHubButtonProps) { localStorage.removeItem(GITHUB_LAST_PAGE); setAuthToken(response.token); - if (response?.isNewUser) { - redirectUrl.searchParams.set(FIRST_LOGIN_PARAM, '1'); - } + redirectUrl.searchParams.set( + FIRST_LOGIN_PARAM, + response?.isNewUser ? '1' : '0', + ); const shouldTriggerPurchase = localStorage.getItem(CHECKOUT_AFTER_LOGIN_KEY) !== '0'; diff --git a/src/components/AuthenticationFlow/GoogleButton.tsx b/src/components/AuthenticationFlow/GoogleButton.tsx index 7af4a8d24..8655f68dd 100644 --- a/src/components/AuthenticationFlow/GoogleButton.tsx +++ b/src/components/AuthenticationFlow/GoogleButton.tsx @@ -81,9 +81,10 @@ export function GoogleButton(props: GoogleButtonProps) { redirectUrl = new URL(authRedirectUrl, window.location.origin); } - if (response?.isNewUser) { - redirectUrl.searchParams.set(FIRST_LOGIN_PARAM, '1'); - } + redirectUrl.searchParams.set( + FIRST_LOGIN_PARAM, + response?.isNewUser ? '1' : '0', + ); const shouldTriggerPurchase = localStorage.getItem(CHECKOUT_AFTER_LOGIN_KEY) !== '0'; diff --git a/src/components/AuthenticationFlow/LinkedInButton.tsx b/src/components/AuthenticationFlow/LinkedInButton.tsx index 32c6e2b8d..6447f3e7d 100644 --- a/src/components/AuthenticationFlow/LinkedInButton.tsx +++ b/src/components/AuthenticationFlow/LinkedInButton.tsx @@ -81,9 +81,10 @@ export function LinkedInButton(props: LinkedInButtonProps) { redirectUrl = new URL(authRedirectUrl, window.location.origin); } - if (response?.isNewUser) { - redirectUrl.searchParams.set(FIRST_LOGIN_PARAM, '1'); - } + redirectUrl.searchParams.set( + FIRST_LOGIN_PARAM, + response?.isNewUser ? '1' : '0', + ); const shouldTriggerPurchase = localStorage.getItem(CHECKOUT_AFTER_LOGIN_KEY) !== '0'; diff --git a/src/components/AuthenticationFlow/TriggerVerifyAccount.tsx b/src/components/AuthenticationFlow/TriggerVerifyAccount.tsx index 2524645f6..b97fb99e5 100644 --- a/src/components/AuthenticationFlow/TriggerVerifyAccount.tsx +++ b/src/components/AuthenticationFlow/TriggerVerifyAccount.tsx @@ -1,7 +1,11 @@ import { useEffect, useState } from 'react'; import Cookies from 'js-cookie'; import { httpPost } from '../../lib/http'; -import { FIRST_LOGIN_PARAM, TOKEN_COOKIE_NAME, setAuthToken } from '../../lib/jwt'; +import { + FIRST_LOGIN_PARAM, + TOKEN_COOKIE_NAME, + setAuthToken, +} from '../../lib/jwt'; import { Spinner } from '../ReactIcons/Spinner'; import { ErrorIcon2 } from '../ReactIcons/ErrorIcon2'; import { triggerUtmRegistration } from '../../lib/browser.ts'; @@ -32,9 +36,10 @@ export function TriggerVerifyAccount() { setAuthToken(response.token); const url = new URL('/', window.location.origin); - if (response?.isNewUser) { - url.searchParams.set(FIRST_LOGIN_PARAM, '1'); - } + url.searchParams.set( + FIRST_LOGIN_PARAM, + response?.isNewUser ? '1' : '0', + ); window.location.href = url.toString(); }) .catch((err) => {