Fix login (#844)
* Fix login * Fix according to PR * Fix tests * Fix tests
This commit is contained in:
@ -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<boolean>(false);
|
||||
|
||||
const [title, setTitle] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!loading) {
|
||||
if (!hasUserManuallySetTitle) {
|
||||
setTitle(commentThread?.title ?? '');
|
||||
}
|
||||
}, [loading, setTitle, commentThread?.title]);
|
||||
|
||||
const [hasUserManuallySetTitle, setHasUserManuallySetTitle] =
|
||||
useState<boolean>(false);
|
||||
}, [setTitle, commentThread?.title, hasUserManuallySetTitle]);
|
||||
|
||||
const [updateCommentThreadMutation] = useUpdateCommentThreadMutation();
|
||||
|
||||
|
||||
@ -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) => {
|
||||
|
||||
@ -46,6 +46,7 @@ export const VERIFY = gql`
|
||||
domainName
|
||||
displayName
|
||||
logo
|
||||
inviteHash
|
||||
}
|
||||
}
|
||||
settings {
|
||||
|
||||
@ -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<Form>({
|
||||
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,
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
@ -50,6 +50,7 @@ export function DefaultLayout({ children }: OwnProps) {
|
||||
const isMatchingLocation = useIsMatchingLocation();
|
||||
|
||||
const onboardingStatus = useOnboardingStatus();
|
||||
|
||||
useEffect(() => {
|
||||
const isMachinOngoingUserCreationRoute =
|
||||
isMatchingLocation(AppPath.SignUp) ||
|
||||
|
||||
Reference in New Issue
Block a user