Fix comment creation bug (#371)
This commit is contained in:
@ -1,26 +1,13 @@
|
||||
import { useEffect } from 'react';
|
||||
import jwt from 'jwt-decode';
|
||||
import { useRecoilState } from 'recoil';
|
||||
|
||||
import { useGetCurrentUserQuery } from '~/generated/graphql';
|
||||
import { AuthTokenPair, useGetCurrentUserQuery } from '~/generated/graphql';
|
||||
|
||||
import { currentUserState } from '../states/currentUserState';
|
||||
import { tokenPairState } from '../states/tokenPairState';
|
||||
|
||||
export function useFetchCurrentUser() {
|
||||
const [, setCurrentUser] = useRecoilState(currentUserState);
|
||||
const [tokenPair] = useRecoilState(tokenPairState);
|
||||
export function useFetchCurrentUser(tokenPair: AuthTokenPair | null) {
|
||||
const userId = tokenPair?.accessToken.token
|
||||
? jwt<{ sub: string }>(tokenPair.accessToken.token).sub
|
||||
: null;
|
||||
const { data } = useGetCurrentUserQuery({
|
||||
variables: { uuid: userId },
|
||||
});
|
||||
const user = data?.users?.[0];
|
||||
|
||||
useEffect(() => {
|
||||
if (user) {
|
||||
setCurrentUser(user);
|
||||
}
|
||||
}, [user, setCurrentUser]);
|
||||
return data?.users?.[0];
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ const cookieStorageEffect =
|
||||
(key: string): AtomEffect<AuthTokenPair | null> =>
|
||||
({ setSelf, onSet }) => {
|
||||
const savedValue = cookieStorage.getItem(key);
|
||||
if (savedValue != null) {
|
||||
if (savedValue != null && JSON.parse(savedValue)['accessToken']) {
|
||||
setSelf(JSON.parse(savedValue));
|
||||
}
|
||||
|
||||
|
||||
@ -45,7 +45,7 @@ export function DropdownMenuCheckableItem({
|
||||
return (
|
||||
<DropdownMenuCheckableItemContainer onClick={handleClick}>
|
||||
<StyledLeftContainer>
|
||||
<Checkbox onChange={onChange} id={id} name={id} checked={checked} />
|
||||
<Checkbox id={id} name={id} checked={checked} />
|
||||
<StyledChildrenContainer>{children}</StyledChildrenContainer>
|
||||
</StyledLeftContainer>
|
||||
</DropdownMenuCheckableItemContainer>
|
||||
|
||||
Reference in New Issue
Block a user