Skip to content

Commit

Permalink
Fixes #28: update DownloadButton to use useEffect for login state man…
Browse files Browse the repository at this point in the history
…agement
  • Loading branch information
tomast1337 committed Jan 19, 2025
1 parent a88dc45 commit 2cd9588
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions web/src/modules/song/components/SongPageButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { SongViewDtoType } from '@shared/validation/song/dto/types';
import Image from 'next/image';
import Link from 'next/link';
import { useState } from 'react';
import { useEffect, useState } from 'react';
import { toast } from 'react-hot-toast';

import { getTokenLocal } from '@web/src/lib/axios/token.utils';
Expand Down Expand Up @@ -238,13 +238,16 @@ const DownloadButton = ({
downloadCount: number;
handleClick: React.MouseEventHandler<HTMLButtonElement>;
}) => {
let isLoggedIn = true;
const [isLoggedIn, setIsLoggedIn] = useState(true);

try {
getTokenLocal();
} catch {
isLoggedIn = false;
}
useEffect(() => {
try {
getTokenLocal();
setIsLoggedIn(true);
} catch {
setIsLoggedIn(false);
}
}, []);

return (
<div className='flex gap-0.5'>
Expand Down

0 comments on commit 2cd9588

Please sign in to comment.