Skip to content

Commit

Permalink
Fix useCurrentUser hook
Browse files Browse the repository at this point in the history
  • Loading branch information
zoul committed Oct 31, 2024
1 parent 90a1d2a commit ce13e7b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions components/hooks/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import { useEffect, useState } from "react";

import { useSession } from "next-auth/react";

import { type OurUser } from "~/src/auth";
import { assertIsOurUser } from "~/src/utils";

/** Is the user with given ID currently signed in? */
export const useCurrentUser = (id: string) => {
const { data: session } = useSession();
const [isCurrentUser, setCurrentUser] = useState(false);
useEffect(() => {
setCurrentUser((session?.user as OurUser)?.id === id);
if (session?.user) {
assertIsOurUser(session.user);
setCurrentUser(session.user.id === id);
}
}, [session, id]);
return isCurrentUser;
};

0 comments on commit ce13e7b

Please sign in to comment.