From 4ac01f2931a3b60be5c1005d301f732776263ca9 Mon Sep 17 00:00:00 2001 From: Charles Bochet Date: Sat, 22 Jul 2023 19:43:28 -0700 Subject: [PATCH] Fix login (#844) * Fix login * Fix according to PR * Fix tests * Fix tests --- front/src/__stories__/App.darkMode.stories.tsx | 9 --------- front/src/__stories__/App.mdx | 11 ----------- front/src/generated/graphql.tsx | 3 ++- .../right-drawer/components/CommentThread.tsx | 11 +++++------ front/src/modules/auth/hooks/useAuth.ts | 7 +++---- front/src/modules/auth/queries/update.ts | 1 + .../modules/auth/sign-in-up/hooks/useSignInUp.tsx | 12 ++---------- .../modules/ui/layout/components/DefaultLayout.tsx | 1 + front/src/pages/auth/CreateWorkspace.tsx | 6 +----- front/src/pages/auth/Verify.tsx | 1 - 10 files changed, 15 insertions(+), 47 deletions(-) delete mode 100644 front/src/__stories__/App.mdx diff --git a/front/src/__stories__/App.darkMode.stories.tsx b/front/src/__stories__/App.darkMode.stories.tsx index a69016f70..53abdf2f4 100644 --- a/front/src/__stories__/App.darkMode.stories.tsx +++ b/front/src/__stories__/App.darkMode.stories.tsx @@ -2,7 +2,6 @@ import { Meta } from '@storybook/react'; import { App } from '~/App'; import { graphqlMocks } from '~/testing/graphqlMocks'; -import { mockedUserJWT } from '~/testing/mock-data/jwt'; import { Story } from './App.stories'; import { renderWithDarkMode } from './shared'; @@ -16,14 +15,6 @@ export default meta; export const DarkMode: Story = { render: () => renderWithDarkMode(true), - loaders: [ - async () => ({ - accessTokenStored: window.localStorage.setItem( - 'accessToken', - mockedUserJWT, - ), - }), - ], parameters: { msw: graphqlMocks, }, diff --git a/front/src/__stories__/App.mdx b/front/src/__stories__/App.mdx deleted file mode 100644 index f1565e948..000000000 --- a/front/src/__stories__/App.mdx +++ /dev/null @@ -1,11 +0,0 @@ -{ /* App.mdx */ } - -import { Canvas, Meta } from '@storybook/blocks'; - -import * as App from './App.stories'; - - - -# App View - - \ No newline at end of file diff --git a/front/src/generated/graphql.tsx b/front/src/generated/graphql.tsx index a9bc5350d..27fdfe102 100644 --- a/front/src/generated/graphql.tsx +++ b/front/src/generated/graphql.tsx @@ -2024,7 +2024,7 @@ export type VerifyMutationVariables = Exact<{ }>; -export type VerifyMutation = { __typename?: 'Mutation', verify: { __typename?: 'Verify', user: { __typename?: 'User', id: string, email: string, displayName: string, firstName?: string | null, lastName?: string | null, workspaceMember?: { __typename?: 'WorkspaceMember', id: string, workspace: { __typename?: 'Workspace', id: string, domainName?: string | null, displayName?: string | null, logo?: string | null } } | null, settings: { __typename?: 'UserSettings', id: string, colorScheme: ColorScheme, locale: string } }, tokens: { __typename?: 'AuthTokenPair', accessToken: { __typename?: 'AuthToken', token: string, expiresAt: string }, refreshToken: { __typename?: 'AuthToken', token: string, expiresAt: string } } } }; +export type VerifyMutation = { __typename?: 'Mutation', verify: { __typename?: 'Verify', user: { __typename?: 'User', id: string, email: string, displayName: string, firstName?: string | null, lastName?: string | null, workspaceMember?: { __typename?: 'WorkspaceMember', id: string, workspace: { __typename?: 'Workspace', id: string, domainName?: string | null, displayName?: string | null, logo?: string | null, inviteHash?: string | null } } | null, settings: { __typename?: 'UserSettings', id: string, colorScheme: ColorScheme, locale: string } }, tokens: { __typename?: 'AuthTokenPair', accessToken: { __typename?: 'AuthToken', token: string, expiresAt: string }, refreshToken: { __typename?: 'AuthToken', token: string, expiresAt: string } } } }; export type RenewTokenMutationVariables = Exact<{ refreshToken: Scalars['String']; @@ -2922,6 +2922,7 @@ export const VerifyDocument = gql` domainName displayName logo + inviteHash } } settings { diff --git a/front/src/modules/activities/right-drawer/components/CommentThread.tsx b/front/src/modules/activities/right-drawer/components/CommentThread.tsx index 2799bd4d2..df2de9c4e 100644 --- a/front/src/modules/activities/right-drawer/components/CommentThread.tsx +++ b/front/src/modules/activities/right-drawer/components/CommentThread.tsx @@ -92,24 +92,23 @@ export function CommentThread({ showComment = true, autoFillTitle = false, }: OwnProps) { - const { data, loading } = useGetCommentThreadQuery({ + const { data } = useGetCommentThreadQuery({ variables: { commentThreadId: commentThreadId ?? '', }, skip: !commentThreadId, }); const commentThread = data?.findManyCommentThreads[0]; + const [hasUserManuallySetTitle, setHasUserManuallySetTitle] = + useState(false); const [title, setTitle] = useState(null); useEffect(() => { - if (!loading) { + if (!hasUserManuallySetTitle) { setTitle(commentThread?.title ?? ''); } - }, [loading, setTitle, commentThread?.title]); - - const [hasUserManuallySetTitle, setHasUserManuallySetTitle] = - useState(false); + }, [setTitle, commentThread?.title, hasUserManuallySetTitle]); const [updateCommentThreadMutation] = useUpdateCommentThreadMutation(); diff --git a/front/src/modules/auth/hooks/useAuth.ts b/front/src/modules/auth/hooks/useAuth.ts index aa4af1f80..18516f255 100644 --- a/front/src/modules/auth/hooks/useAuth.ts +++ b/front/src/modules/auth/hooks/useAuth.ts @@ -62,13 +62,14 @@ export function useAuth() { throw new Error('No verify result'); } + setCurrentUser(verifyResult.data?.verify.user); setTokenPair(verifyResult.data?.verify.tokens); setIsAuthenticating(false); return verifyResult.data?.verify; }, - [setIsAuthenticating, setTokenPair, verify], + [setIsAuthenticating, setTokenPair, verify, setCurrentUser], ); const handleCrendentialsSignIn = useCallback( @@ -111,11 +112,9 @@ export function useAuth() { signUpResult.data?.signUp.loginToken.token, ); - setCurrentUser(user); - return { user }; }, - [signUp, handleVerify, setCurrentUser], + [signUp, handleVerify], ); const handleGoogleLogin = useCallback((workspaceInviteHash?: string) => { diff --git a/front/src/modules/auth/queries/update.ts b/front/src/modules/auth/queries/update.ts index 5f21e9cc9..a9ae96dee 100644 --- a/front/src/modules/auth/queries/update.ts +++ b/front/src/modules/auth/queries/update.ts @@ -46,6 +46,7 @@ export const VERIFY = gql` domainName displayName logo + inviteHash } } settings { diff --git a/front/src/modules/auth/sign-in-up/hooks/useSignInUp.tsx b/front/src/modules/auth/sign-in-up/hooks/useSignInUp.tsx index 936fe3c70..e9b48108f 100644 --- a/front/src/modules/auth/sign-in-up/hooks/useSignInUp.tsx +++ b/front/src/modules/auth/sign-in-up/hooks/useSignInUp.tsx @@ -14,7 +14,6 @@ import { useSnackBar } from '@/ui/snack-bar/hooks/useSnackBar'; import { useIsMatchingLocation } from '~/hooks/useIsMatchingLocation'; import { useAuth } from '../../hooks/useAuth'; -import { currentUserState } from '../../states/currentUserState'; import { PASSWORD_REGEX } from '../../utils/passwordRegex'; export enum SignInUpMode { @@ -57,7 +56,6 @@ export function useSignInUp() { : SignInUpMode.SignUp, ); const [showErrors, setShowErrors] = useState(false); - const [, setCurrentUser] = useRecoilState(currentUserState); const form = useForm
({ mode: 'onChange', @@ -108,18 +106,13 @@ export function useSignInUp() { throw new Error('Email and password are required'); } if (signInUpMode === SignInUpMode.SignIn) { - const { user } = await signInWithCredentials( - data.email, - data.password, - ); - setCurrentUser(user); + await signInWithCredentials(data.email, data.password); } else { - const { user } = await signUpWithCredentials( + await signUpWithCredentials( data.email, data.password, workspaceInviteHash, ); - setCurrentUser(user); } navigate('/create/workspace'); } catch (err: any) { @@ -135,7 +128,6 @@ export function useSignInUp() { workspaceInviteHash, enqueueSnackBar, signInUpMode, - setCurrentUser, ], ); diff --git a/front/src/modules/ui/layout/components/DefaultLayout.tsx b/front/src/modules/ui/layout/components/DefaultLayout.tsx index f45e048d7..4536166aa 100644 --- a/front/src/modules/ui/layout/components/DefaultLayout.tsx +++ b/front/src/modules/ui/layout/components/DefaultLayout.tsx @@ -50,6 +50,7 @@ export function DefaultLayout({ children }: OwnProps) { const isMatchingLocation = useIsMatchingLocation(); const onboardingStatus = useOnboardingStatus(); + useEffect(() => { const isMachinOngoingUserCreationRoute = isMatchingLocation(AppPath.SignUp) || diff --git a/front/src/pages/auth/CreateWorkspace.tsx b/front/src/pages/auth/CreateWorkspace.tsx index cee9dcdaa..7a6c8b52c 100644 --- a/front/src/pages/auth/CreateWorkspace.tsx +++ b/front/src/pages/auth/CreateWorkspace.tsx @@ -16,10 +16,7 @@ import { TextInput } from '@/ui/input/components/TextInput'; import { useSnackBar } from '@/ui/snack-bar/hooks/useSnackBar'; import { SubSectionTitle } from '@/ui/title/components/SubSectionTitle'; import { GET_CURRENT_USER } from '@/users/queries'; -import { - useGetCurrentUserLazyQuery, - useUpdateWorkspaceMutation, -} from '~/generated/graphql'; +import { useUpdateWorkspaceMutation } from '~/generated/graphql'; const StyledContentContainer = styled.div` width: 100%; @@ -48,7 +45,6 @@ export function CreateWorkspace() { const { enqueueSnackBar } = useSnackBar(); const [updateWorkspace] = useUpdateWorkspaceMutation(); - useGetCurrentUserLazyQuery(); // Form const { diff --git a/front/src/pages/auth/Verify.tsx b/front/src/pages/auth/Verify.tsx index 4cb0a648e..9c8e0d0a1 100644 --- a/front/src/pages/auth/Verify.tsx +++ b/front/src/pages/auth/Verify.tsx @@ -21,7 +21,6 @@ export function Verify() { navigate(AppPath.SignIn); } else { await verify(loginToken); - navigate('/'); } }