useEffect fires even when the session is undefined #2258
-
Hi there, I have this code that should run when the session / session user is defined: useEffect(() => {
console.log('authed')
const { user: userData } = useUser(session);
setUser(userData);
}, [session.user]); However, in function useUser(session: Session) {
console.log(session) // undefined
const db = firebase.firestore();
db.doc(`accounts/${session.userId}`).get().then((userData) => {
console.log(userData.data())
setUser(userData.data());
});
return { user };
} (let me know if this isn't a next-auth issue) What do I do, and how can I fix it? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
It's a React hook issue. Have a read on https://reactjs.org/docs/hooks-rules.html#only-call-hooks-at-the-top-level 😊 Update: Maybe I misunderstood, but be careful with the naming of your functions. |
Beta Was this translation helpful? Give feedback.
It's a React hook issue. Have a read on https://reactjs.org/docs/hooks-rules.html#only-call-hooks-at-the-top-level 😊
Update: Maybe I misunderstood, but be careful with the naming of your functions.
use
is usually reserved for React hooks. The problem is still not next-auth specific though. you will need an early return when session is undefined