feat: new user flag

feat/new-user
Arik Chakma 2 days ago
parent 23eb9b6626
commit 68597d58d2
  1. 15
      src/components/AuthenticationFlow/EmailLoginForm.tsx
  2. 7
      src/components/AuthenticationFlow/GitHubButton.tsx
  3. 7
      src/components/AuthenticationFlow/GoogleButton.tsx
  4. 7
      src/components/AuthenticationFlow/LinkedInButton.tsx
  5. 7
      src/components/AuthenticationFlow/TriggerVerifyAccount.tsx

@ -24,19 +24,22 @@ export function EmailLoginForm(props: EmailLoginFormProps) {
setIsDisabled?.(true); setIsDisabled?.(true);
setError(''); setError('');
const { response, error } = await httpPost<{ token: string }>( const { response, error } = await httpPost<{
`${import.meta.env.PUBLIC_API_URL}/v1-login`, token: string;
{ isNewUser: boolean;
}>(`${import.meta.env.PUBLIC_API_URL}/v1-login`, {
email, email,
password, password,
}, });
);
// Log the user in and reload the page // Log the user in and reload the page
if (response?.token) { if (response?.token) {
setAuthToken(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; return;
} }

@ -32,7 +32,7 @@ export function GitHubButton(props: GitHubButtonProps) {
setIsLoading(true); setIsLoading(true);
setIsDisabled?.(true); setIsDisabled?.(true);
httpGet<{ token: string }>( httpGet<{ token: string; isNewUser: boolean }>(
`${import.meta.env.PUBLIC_API_URL}/v1-github-callback${ `${import.meta.env.PUBLIC_API_URL}/v1-github-callback${
window.location.search window.location.search
}`, }`,
@ -74,7 +74,10 @@ export function GitHubButton(props: GitHubButtonProps) {
localStorage.removeItem(GITHUB_REDIRECT_AT); localStorage.removeItem(GITHUB_REDIRECT_AT);
localStorage.removeItem(GITHUB_LAST_PAGE); localStorage.removeItem(GITHUB_LAST_PAGE);
setAuthToken(response.token); 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) => { .catch((err) => {
setError('Something went wrong. Please try again later.'); setError('Something went wrong. Please try again later.');

@ -35,7 +35,7 @@ export function GoogleButton(props: GoogleButtonProps) {
setIsLoading(true); setIsLoading(true);
setIsDisabled?.(true); setIsDisabled?.(true);
httpGet<{ token: string }>( httpGet<{ token: string; isNewUser: boolean }>(
`${import.meta.env.PUBLIC_API_URL}/v1-google-callback${ `${import.meta.env.PUBLIC_API_URL}/v1-google-callback${
window.location.search window.location.search
}`, }`,
@ -78,7 +78,10 @@ export function GoogleButton(props: GoogleButtonProps) {
localStorage.removeItem(GOOGLE_REDIRECT_AT); localStorage.removeItem(GOOGLE_REDIRECT_AT);
localStorage.removeItem(GOOGLE_LAST_PAGE); localStorage.removeItem(GOOGLE_LAST_PAGE);
setAuthToken(response.token); 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) => { .catch((err) => {
setError('Something went wrong. Please try again later.'); setError('Something went wrong. Please try again later.');

@ -32,7 +32,7 @@ export function LinkedInButton(props: LinkedInButtonProps) {
setIsLoading(true); setIsLoading(true);
setIsDisabled?.(true); setIsDisabled?.(true);
httpGet<{ token: string }>( httpGet<{ token: string; isNewUser: boolean }>(
`${import.meta.env.PUBLIC_API_URL}/v1-linkedin-callback${ `${import.meta.env.PUBLIC_API_URL}/v1-linkedin-callback${
window.location.search window.location.search
}`, }`,
@ -73,7 +73,10 @@ export function LinkedInButton(props: LinkedInButtonProps) {
localStorage.removeItem(LINKEDIN_REDIRECT_AT); localStorage.removeItem(LINKEDIN_REDIRECT_AT);
localStorage.removeItem(LINKEDIN_LAST_PAGE); localStorage.removeItem(LINKEDIN_LAST_PAGE);
setAuthToken(response.token); 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) => { .catch((err) => {
setError('Something went wrong. Please try again later.'); setError('Something went wrong. Please try again later.');

@ -13,7 +13,7 @@ export function TriggerVerifyAccount() {
const triggerVerify = (code: string) => { const triggerVerify = (code: string) => {
setIsLoading(true); setIsLoading(true);
httpPost<{ token: string }>( httpPost<{ token: string; isNewUser: boolean }>(
`${import.meta.env.PUBLIC_API_URL}/v1-verify-account`, `${import.meta.env.PUBLIC_API_URL}/v1-verify-account`,
{ {
code, code,
@ -30,7 +30,10 @@ export function TriggerVerifyAccount() {
triggerUtmRegistration(); triggerUtmRegistration();
setAuthToken(response.token); 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) => { .catch((err) => {
setIsLoading(false); setIsLoading(false);

Loading…
Cancel
Save