feat: new user flag

feat/new-user
Arik Chakma 2 days ago
parent 23eb9b6626
commit 68597d58d2
  1. 19
      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);
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;
}

@ -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.');

@ -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.');

@ -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.');

@ -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);

Loading…
Cancel
Save