From 66807bef0d393b42ecb646b11ed644e063f89824 Mon Sep 17 00:00:00 2001 From: guru_sainath Date: Sat, 10 Jun 2023 01:26:38 +0530 Subject: [PATCH 1/7] fix: social auth authentication workflow (#1264) * fix: github login mutation * dev: updated social auth workflow and handled multiple loads on user * dev: mutaing user and updated analytics logout issue resolved --------- Co-authored-by: Aaryan Khandelwal --- .../account/github-login-button.tsx | 6 ++-- apps/app/hooks/use-user-auth.tsx | 1 + apps/app/pages/[workspaceSlug]/analytics.tsx | 13 +++++---- apps/app/pages/index.tsx | 28 +++++++++---------- apps/app/pages/onboarding.tsx | 21 ++------------ 5 files changed, 28 insertions(+), 41 deletions(-) diff --git a/apps/app/components/account/github-login-button.tsx b/apps/app/components/account/github-login-button.tsx index 764680d30b8..3da7317e820 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 3e92fd3fe8f..d3116ce0677 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 eb2816b562c..e37555bae76 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 c84adeae73a..6548982bae7 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 = From 15b5db0cae7e1618e26c2969aa774c5bb94a2cb0 Mon Sep 17 00:00:00 2001 From: pablohashescobar <118773738+pablohashescobar@users.noreply.github.com> Date: Mon, 12 Jun 2023 10:02:16 +0530 Subject: [PATCH 2/7] dev: upgrade python runtime (#1256) --- apiserver/runtime.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apiserver/runtime.txt b/apiserver/runtime.txt index a35d6cba1e5..fefae710dc4 100644 --- a/apiserver/runtime.txt +++ b/apiserver/runtime.txt @@ -1 +1 @@ -python-3.11.3 \ No newline at end of file +python-3.11.4 \ No newline at end of file From f774603b7fc83df18f4e50ee55d4b3ccedd4d340 Mon Sep 17 00:00:00 2001 From: guru_sainath Date: Tue, 13 Jun 2023 14:37:25 +0530 Subject: [PATCH 3/7] chore: onboarding workflow in authentication (#1281) --- .../components/account/email-code-form.tsx | 29 +-- .../account/github-login-button.tsx | 6 +- apps/app/components/account/google-login.tsx | 6 +- apps/app/pages/index.tsx | 50 +++-- apps/app/pages/onboarding.tsx | 197 +++++++++--------- 5 files changed, 159 insertions(+), 129 deletions(-) diff --git a/apps/app/components/account/email-code-form.tsx b/apps/app/components/account/email-code-form.tsx index 9132ee99425..e1b7aea9884 100644 --- a/apps/app/components/account/email-code-form.tsx +++ b/apps/app/components/account/email-code-form.tsx @@ -16,7 +16,7 @@ type EmailCodeFormValues = { token?: string; }; -export const EmailCodeForm = ({ onSuccess }: any) => { +export const EmailCodeForm = ({ handleSignIn }: any) => { const [codeSent, setCodeSent] = useState(false); const [codeResent, setCodeResent] = useState(false); const [isCodeResending, setIsCodeResending] = useState(false); @@ -66,18 +66,23 @@ export const EmailCodeForm = ({ onSuccess }: any) => { const handleSignin = async (formData: EmailCodeFormValues) => { setIsLoading(true); - await authenticationService.magicSignIn(formData).catch((error) => { - setIsLoading(false); - setToastAlert({ - title: "Oops!", - type: "error", - message: error?.response?.data?.error ?? "Enter the correct code to sign in", - }); - setError("token" as keyof EmailCodeFormValues, { - type: "manual", - message: error.error, + await authenticationService + .magicSignIn(formData) + .then((response) => { + handleSignIn(response); + }) + .catch((error) => { + setIsLoading(false); + setToastAlert({ + title: "Oops!", + type: "error", + message: error?.response?.data?.error ?? "Enter the correct code to sign in", + }); + setError("token" as keyof EmailCodeFormValues, { + type: "manual", + message: error?.error, + }); }); - }); }; const emailOld = getValues("email"); diff --git a/apps/app/components/account/github-login-button.tsx b/apps/app/components/account/github-login-button.tsx index 3da7317e820..d997b3a3de0 100644 --- a/apps/app/components/account/github-login-button.tsx +++ b/apps/app/components/account/github-login-button.tsx @@ -35,12 +35,12 @@ export const GithubLoginButton: FC = (props) => { }, []); return ( -
+
- diff --git a/apps/app/components/account/google-login.tsx b/apps/app/components/account/google-login.tsx index 237439def44..c12fb4e24ff 100644 --- a/apps/app/components/account/google-login.tsx +++ b/apps/app/components/account/google-login.tsx @@ -47,7 +47,11 @@ export const GoogleLoginButton: FC = (props) => { return ( <>