Skip to content

Commit

Permalink
Replace useGetIsAuthenticatedQuery with useIsAuthenticated
Browse files Browse the repository at this point in the history
  • Loading branch information
jakecoble committed Sep 4, 2024
1 parent abbf712 commit 96562fe
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 21 deletions.
15 changes: 3 additions & 12 deletions src/components/molecules/player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ import PlaybackTimes from '~components/molecules/playbackTimes';
import RecordingProgressBar from '~components/molecules/recordingProgressBar';
import { AndMiniplayerFragment } from '~components/templates/__generated__/andMiniplayer';
import { BaseColors } from '~lib/constants';
import { getSessionToken } from '~lib/cookies';
import hasVideo from '~lib/hasVideo';
import { useGetIsAuthenticatedQuery } from '~lib/hooks/__generated__/useIsAuthenticated';
import useGlobalSpaceDown from '~lib/useGlobalSpaceDown';
import usePlaybackSession from '~lib/usePlaybackSession';
import IconAirPlayAudio from '~public/img/icon-airplay-audio.svg';
import IconChromeCast from '~public/img/icon-chromecast.svg';
import IconFullscreen from '~public/img/icons/icon-fullscreen.svg';
import IconPause from '~public/img/icons/icon-pause-large.svg';
import IconPlay from '~public/img/icons/icon-play-large.svg';
import useIsAuthenticated from '~src/lib/hooks/useIsAuthenticated';

import { PlaybackContext } from '../templates/andPlaybackContext';
import { PlayerFragment } from './__generated__/player';
Expand Down Expand Up @@ -84,15 +83,7 @@ const Player = ({
? BaseColors.WHITE
: BaseColors.DARK;

const sessionToken = getSessionToken(); // i will see if this give any issue
const authResult = useGetIsAuthenticatedQuery(
{},
{
enabled: !!sessionToken,
retry: false,
}
);
const user = authResult.data?.me?.user;
const { isUserLoggedIn } = useIsAuthenticated();

return (
<div
Expand Down Expand Up @@ -244,7 +235,7 @@ const Player = ({
)}

<ButtonSpeed {...{ recording, backgroundColor }} />
{user ? (
{isUserLoggedIn ? (
<ButtonDownload {...{ recording, backgroundColor }} />
) : (
<ButtonDownloadBlank backgroundColor={backgroundColor} />
Expand Down
11 changes: 2 additions & 9 deletions src/components/organisms/navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import NavItem from '~components/molecules/navItem';
import SearchBar from '~components/molecules/searchBar';
import Header from '~components/organisms/header';
import { getSessionToken, setSessionToken } from '~lib/cookies';
import { useGetIsAuthenticatedQuery } from '~lib/hooks/__generated__/useIsAuthenticated';
import root from '~lib/routes';
import useLanguageRoute from '~lib/useLanguageRoute';
import { INavigationItem, useNavigationItems } from '~lib/useNavigationItems';
import IconUser from '~public/img/icons/fa-user-heavy.svg';
import IconDisclosure from '~public/img/icons/icon-disclosure-light-small.svg';
import IconExit from '~public/img/icons/icon-exit.svg';
import { BaseColors } from '~src/lib/constants';
import useIsAuthenticated from '~src/lib/hooks/useIsAuthenticated';

import { analytics } from '../../lib/analytics';
import IconButton from '../molecules/iconButton';
Expand Down Expand Up @@ -62,14 +62,7 @@ const Navigation = ({
}
}, [router.asPath, sessionToken]);

const authResult = useGetIsAuthenticatedQuery(
{},
{
enabled: !!sessionToken,
retry: false,
}
);
const user = authResult.data?.me?.user;
const { user } = useIsAuthenticated();

const navigationItems = useNavigationItems();
const submenuItem = navigationItems.find(
Expand Down
2 changes: 2 additions & 0 deletions src/lib/hooks/useIsAuthenticated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { useGetIsAuthenticatedQuery } from './__generated__/useIsAuthenticated';
export default function useIsAuthenticated(): {
isUserLoggedIn: boolean;
isLoading: boolean;
user?: { name: string; email: string };
} {
const { data, isLoading } = useGetIsAuthenticatedQuery({}, { retry: false });

return {
isUserLoggedIn: !!data?.me?.user.email,
isLoading,
user: data?.me?.user,
};
}

0 comments on commit 96562fe

Please sign in to comment.