Fix login (#844)
* Fix login * Fix according to PR * Fix tests * Fix tests
This commit is contained in:
@ -2,7 +2,6 @@ import { Meta } from '@storybook/react';
|
|||||||
|
|
||||||
import { App } from '~/App';
|
import { App } from '~/App';
|
||||||
import { graphqlMocks } from '~/testing/graphqlMocks';
|
import { graphqlMocks } from '~/testing/graphqlMocks';
|
||||||
import { mockedUserJWT } from '~/testing/mock-data/jwt';
|
|
||||||
|
|
||||||
import { Story } from './App.stories';
|
import { Story } from './App.stories';
|
||||||
import { renderWithDarkMode } from './shared';
|
import { renderWithDarkMode } from './shared';
|
||||||
@ -16,14 +15,6 @@ export default meta;
|
|||||||
|
|
||||||
export const DarkMode: Story = {
|
export const DarkMode: Story = {
|
||||||
render: () => renderWithDarkMode(true),
|
render: () => renderWithDarkMode(true),
|
||||||
loaders: [
|
|
||||||
async () => ({
|
|
||||||
accessTokenStored: window.localStorage.setItem(
|
|
||||||
'accessToken',
|
|
||||||
mockedUserJWT,
|
|
||||||
),
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
parameters: {
|
parameters: {
|
||||||
msw: graphqlMocks,
|
msw: graphqlMocks,
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,11 +0,0 @@
|
|||||||
{ /* App.mdx */ }
|
|
||||||
|
|
||||||
import { Canvas, Meta } from '@storybook/blocks';
|
|
||||||
|
|
||||||
import * as App from './App.stories';
|
|
||||||
|
|
||||||
<Meta of={App} />
|
|
||||||
|
|
||||||
# App View
|
|
||||||
|
|
||||||
<Canvas of={App.Default} />
|
|
||||||
@ -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<{
|
export type RenewTokenMutationVariables = Exact<{
|
||||||
refreshToken: Scalars['String'];
|
refreshToken: Scalars['String'];
|
||||||
@ -2922,6 +2922,7 @@ export const VerifyDocument = gql`
|
|||||||
domainName
|
domainName
|
||||||
displayName
|
displayName
|
||||||
logo
|
logo
|
||||||
|
inviteHash
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
settings {
|
settings {
|
||||||
|
|||||||
@ -92,24 +92,23 @@ export function CommentThread({
|
|||||||
showComment = true,
|
showComment = true,
|
||||||
autoFillTitle = false,
|
autoFillTitle = false,
|
||||||
}: OwnProps) {
|
}: OwnProps) {
|
||||||
const { data, loading } = useGetCommentThreadQuery({
|
const { data } = useGetCommentThreadQuery({
|
||||||
variables: {
|
variables: {
|
||||||
commentThreadId: commentThreadId ?? '',
|
commentThreadId: commentThreadId ?? '',
|
||||||
},
|
},
|
||||||
skip: !commentThreadId,
|
skip: !commentThreadId,
|
||||||
});
|
});
|
||||||
const commentThread = data?.findManyCommentThreads[0];
|
const commentThread = data?.findManyCommentThreads[0];
|
||||||
|
const [hasUserManuallySetTitle, setHasUserManuallySetTitle] =
|
||||||
|
useState<boolean>(false);
|
||||||
|
|
||||||
const [title, setTitle] = useState<string | null>(null);
|
const [title, setTitle] = useState<string | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!loading) {
|
if (!hasUserManuallySetTitle) {
|
||||||
setTitle(commentThread?.title ?? '');
|
setTitle(commentThread?.title ?? '');
|
||||||
}
|
}
|
||||||
}, [loading, setTitle, commentThread?.title]);
|
}, [setTitle, commentThread?.title, hasUserManuallySetTitle]);
|
||||||
|
|
||||||
const [hasUserManuallySetTitle, setHasUserManuallySetTitle] =
|
|
||||||
useState<boolean>(false);
|
|
||||||
|
|
||||||
const [updateCommentThreadMutation] = useUpdateCommentThreadMutation();
|
const [updateCommentThreadMutation] = useUpdateCommentThreadMutation();
|
||||||
|
|
||||||
|
|||||||
@ -62,13 +62,14 @@ export function useAuth() {
|
|||||||
throw new Error('No verify result');
|
throw new Error('No verify result');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setCurrentUser(verifyResult.data?.verify.user);
|
||||||
setTokenPair(verifyResult.data?.verify.tokens);
|
setTokenPair(verifyResult.data?.verify.tokens);
|
||||||
|
|
||||||
setIsAuthenticating(false);
|
setIsAuthenticating(false);
|
||||||
|
|
||||||
return verifyResult.data?.verify;
|
return verifyResult.data?.verify;
|
||||||
},
|
},
|
||||||
[setIsAuthenticating, setTokenPair, verify],
|
[setIsAuthenticating, setTokenPair, verify, setCurrentUser],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleCrendentialsSignIn = useCallback(
|
const handleCrendentialsSignIn = useCallback(
|
||||||
@ -111,11 +112,9 @@ export function useAuth() {
|
|||||||
signUpResult.data?.signUp.loginToken.token,
|
signUpResult.data?.signUp.loginToken.token,
|
||||||
);
|
);
|
||||||
|
|
||||||
setCurrentUser(user);
|
|
||||||
|
|
||||||
return { user };
|
return { user };
|
||||||
},
|
},
|
||||||
[signUp, handleVerify, setCurrentUser],
|
[signUp, handleVerify],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleGoogleLogin = useCallback((workspaceInviteHash?: string) => {
|
const handleGoogleLogin = useCallback((workspaceInviteHash?: string) => {
|
||||||
|
|||||||
@ -46,6 +46,7 @@ export const VERIFY = gql`
|
|||||||
domainName
|
domainName
|
||||||
displayName
|
displayName
|
||||||
logo
|
logo
|
||||||
|
inviteHash
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
settings {
|
settings {
|
||||||
|
|||||||
@ -14,7 +14,6 @@ import { useSnackBar } from '@/ui/snack-bar/hooks/useSnackBar';
|
|||||||
import { useIsMatchingLocation } from '~/hooks/useIsMatchingLocation';
|
import { useIsMatchingLocation } from '~/hooks/useIsMatchingLocation';
|
||||||
|
|
||||||
import { useAuth } from '../../hooks/useAuth';
|
import { useAuth } from '../../hooks/useAuth';
|
||||||
import { currentUserState } from '../../states/currentUserState';
|
|
||||||
import { PASSWORD_REGEX } from '../../utils/passwordRegex';
|
import { PASSWORD_REGEX } from '../../utils/passwordRegex';
|
||||||
|
|
||||||
export enum SignInUpMode {
|
export enum SignInUpMode {
|
||||||
@ -57,7 +56,6 @@ export function useSignInUp() {
|
|||||||
: SignInUpMode.SignUp,
|
: SignInUpMode.SignUp,
|
||||||
);
|
);
|
||||||
const [showErrors, setShowErrors] = useState(false);
|
const [showErrors, setShowErrors] = useState(false);
|
||||||
const [, setCurrentUser] = useRecoilState(currentUserState);
|
|
||||||
|
|
||||||
const form = useForm<Form>({
|
const form = useForm<Form>({
|
||||||
mode: 'onChange',
|
mode: 'onChange',
|
||||||
@ -108,18 +106,13 @@ export function useSignInUp() {
|
|||||||
throw new Error('Email and password are required');
|
throw new Error('Email and password are required');
|
||||||
}
|
}
|
||||||
if (signInUpMode === SignInUpMode.SignIn) {
|
if (signInUpMode === SignInUpMode.SignIn) {
|
||||||
const { user } = await signInWithCredentials(
|
await signInWithCredentials(data.email, data.password);
|
||||||
data.email,
|
|
||||||
data.password,
|
|
||||||
);
|
|
||||||
setCurrentUser(user);
|
|
||||||
} else {
|
} else {
|
||||||
const { user } = await signUpWithCredentials(
|
await signUpWithCredentials(
|
||||||
data.email,
|
data.email,
|
||||||
data.password,
|
data.password,
|
||||||
workspaceInviteHash,
|
workspaceInviteHash,
|
||||||
);
|
);
|
||||||
setCurrentUser(user);
|
|
||||||
}
|
}
|
||||||
navigate('/create/workspace');
|
navigate('/create/workspace');
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
@ -135,7 +128,6 @@ export function useSignInUp() {
|
|||||||
workspaceInviteHash,
|
workspaceInviteHash,
|
||||||
enqueueSnackBar,
|
enqueueSnackBar,
|
||||||
signInUpMode,
|
signInUpMode,
|
||||||
setCurrentUser,
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -50,6 +50,7 @@ export function DefaultLayout({ children }: OwnProps) {
|
|||||||
const isMatchingLocation = useIsMatchingLocation();
|
const isMatchingLocation = useIsMatchingLocation();
|
||||||
|
|
||||||
const onboardingStatus = useOnboardingStatus();
|
const onboardingStatus = useOnboardingStatus();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const isMachinOngoingUserCreationRoute =
|
const isMachinOngoingUserCreationRoute =
|
||||||
isMatchingLocation(AppPath.SignUp) ||
|
isMatchingLocation(AppPath.SignUp) ||
|
||||||
|
|||||||
@ -16,10 +16,7 @@ import { TextInput } from '@/ui/input/components/TextInput';
|
|||||||
import { useSnackBar } from '@/ui/snack-bar/hooks/useSnackBar';
|
import { useSnackBar } from '@/ui/snack-bar/hooks/useSnackBar';
|
||||||
import { SubSectionTitle } from '@/ui/title/components/SubSectionTitle';
|
import { SubSectionTitle } from '@/ui/title/components/SubSectionTitle';
|
||||||
import { GET_CURRENT_USER } from '@/users/queries';
|
import { GET_CURRENT_USER } from '@/users/queries';
|
||||||
import {
|
import { useUpdateWorkspaceMutation } from '~/generated/graphql';
|
||||||
useGetCurrentUserLazyQuery,
|
|
||||||
useUpdateWorkspaceMutation,
|
|
||||||
} from '~/generated/graphql';
|
|
||||||
|
|
||||||
const StyledContentContainer = styled.div`
|
const StyledContentContainer = styled.div`
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@ -48,7 +45,6 @@ export function CreateWorkspace() {
|
|||||||
const { enqueueSnackBar } = useSnackBar();
|
const { enqueueSnackBar } = useSnackBar();
|
||||||
|
|
||||||
const [updateWorkspace] = useUpdateWorkspaceMutation();
|
const [updateWorkspace] = useUpdateWorkspaceMutation();
|
||||||
useGetCurrentUserLazyQuery();
|
|
||||||
|
|
||||||
// Form
|
// Form
|
||||||
const {
|
const {
|
||||||
|
|||||||
@ -21,7 +21,6 @@ export function Verify() {
|
|||||||
navigate(AppPath.SignIn);
|
navigate(AppPath.SignIn);
|
||||||
} else {
|
} else {
|
||||||
await verify(loginToken);
|
await verify(loginToken);
|
||||||
navigate('/');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user