diff --git a/apps/app/components/account/github-login-button.tsx b/apps/app/components/account/github-login-button.tsx index 764680d30..3da7317e8 100644 --- a/apps/app/components/account/github-login-button.tsx +++ b/apps/app/components/account/github-login-button.tsx @@ -19,12 +19,14 @@ export const GithubLoginButton: FC = (props) => { } = useRouter(); // states const [loginCallBackURL, setLoginCallBackURL] = useState(undefined); + const [gitCode, setGitCode] = useState(null); useEffect(() => { - if (code) { + if (code && !gitCode) { + setGitCode(code.toString()); handleSignIn(code.toString()); } - }, [code, handleSignIn]); + }, [code, gitCode, handleSignIn]); useEffect(() => { const origin = diff --git a/apps/app/hooks/use-user-auth.tsx b/apps/app/hooks/use-user-auth.tsx index 3e92fd3fe..d3116ce06 100644 --- a/apps/app/hooks/use-user-auth.tsx +++ b/apps/app/hooks/use-user-auth.tsx @@ -24,6 +24,7 @@ const useUserAuth = (routeAuth: "sign-in" | "onboarding" | "admin" | null = "adm mutate, } = useSWR(CURRENT_USER, () => userService.currentUser(), { refreshInterval: 0, + shouldRetryOnError: false, }); useEffect(() => { diff --git a/apps/app/pages/[workspaceSlug]/analytics.tsx b/apps/app/pages/[workspaceSlug]/analytics.tsx index eb2816b56..e37555bae 100644 --- a/apps/app/pages/[workspaceSlug]/analytics.tsx +++ b/apps/app/pages/[workspaceSlug]/analytics.tsx @@ -69,12 +69,13 @@ const Analytics = () => { useEffect(() => { if (!workspaceSlug) return; - trackEventServices.trackAnalyticsEvent( - { workspaceSlug: workspaceSlug?.toString() }, - "WORKSPACE_SCOPE_AND_DEMAND_ANALYTICS", - user - ); - }, [workspaceSlug]); + if (user && workspaceSlug) + trackEventServices.trackAnalyticsEvent( + { workspaceSlug: workspaceSlug?.toString() }, + "WORKSPACE_SCOPE_AND_DEMAND_ANALYTICS", + user + ); + }, [user, workspaceSlug]); return ( { const handleGoogleSignIn = async ({ clientId, credential }: any) => { try { if (clientId && credential) { - mutateUser( - await authenticationService.socialAuth({ - medium: "google", - credential, - clientId, - }) - ); + const socialAuthPayload = { + medium: "google", + credential, + clientId, + }; + const response = await authenticationService.socialAuth(socialAuthPayload); + if (response && response?.user) mutateUser(); } else { throw Error("Cant find credentials"); } @@ -53,13 +53,13 @@ const HomePage: NextPage = () => { const handleGithubSignIn = async (credential: string) => { try { if (process.env.NEXT_PUBLIC_GITHUB_ID && credential) { - mutateUser( - await authenticationService.socialAuth({ - medium: "github", - credential, - clientId: process.env.NEXT_PUBLIC_GITHUB_ID, - }) - ); + const socialAuthPayload = { + medium: "github", + credential, + clientId: process.env.NEXT_PUBLIC_GITHUB_ID, + }; + const response = await authenticationService.socialAuth(socialAuthPayload); + if (response && response?.user) mutateUser(); } else { throw Error("Cant find credentials"); } diff --git a/apps/app/pages/onboarding.tsx b/apps/app/pages/onboarding.tsx index c84adeae7..6548982ba 100644 --- a/apps/app/pages/onboarding.tsx +++ b/apps/app/pages/onboarding.tsx @@ -1,7 +1,6 @@ import { useState } from "react"; -import Image from "next/image"; -import Router, { useRouter } from "next/router"; +import Router from "next/router"; import { mutate } from "swr"; @@ -38,8 +37,6 @@ const Onboarding: NextPage = () => { const [workspace, setWorkspace] = useState(); - const router = useRouter(); - const { user, mutateUser } = useUserAuth("onboarding"); return ( @@ -89,21 +86,7 @@ const Onboarding: NextPage = () => { userService .updateUserOnBoard({ userRole }, user) .then(async () => { - mutate( - CURRENT_USER, - (prevData) => { - if (!prevData) return prevData; - - return { - ...prevData, - user: { - ...prevData.user, - is_onboarded: true, - }, - }; - }, - false - ); + mutateUser(); const userWorkspaces = await workspaceService.userWorkspaces(); const lastActiveWorkspace =