Skip to content

Commit cc7615d

Browse files
Add session check before using route handler
1 parent 600cdcb commit cc7615d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/hooks/use-get-repo.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ import axios from 'axios';
22
import { useAtomValue } from 'jotai';
33
import { useEffect, useState } from 'react';
44
import { repoAtom } from '@/state/repoAtom';
5+
import { useSession } from 'next-auth/react';
56

67
export function useGetRepo() {
78
const [isReported, setIsReported] = useState(false);
9+
const session = useSession();
810
const repo = useAtomValue(repoAtom);
911

1012
useEffect(() => {
1113
async function checkRepo() {
14+
if (!session.data?.user) return;
1215
if (!repo) return;
1316
const repoId = repo?.id;
1417
const res = await axios.get(`/api/check-repo?repoId=${repoId}`);
@@ -18,7 +21,7 @@ export function useGetRepo() {
1821
return setIsReported(true);
1922
}
2023
checkRepo();
21-
}, [repo]);
24+
}, [repo, session]);
2225

2326
return isReported;
2427
}

0 commit comments

Comments
 (0)