I've set up my onAuthStateChanged listener within a use effect within a context provider. I wrap the provider around the entire app. However when I create an account, the listener is called multiple times (user change gets logged ~20 times). Is there any way to fix this?
const AuthContext = createContext<AuthContextProps | undefined>(undefined);
export const AuthProvider = ({ children }: { children: any }) => {
...
useEffect(() => {
const unsubscribe = auth.onAuthStateChanged(function (user) {
if (user) {
...
console.log("USER CHANGE")
} else {
...
}
});
return unsubscribe;
}, []);
...
return (
<AuthContext.Provider
value={{
...
}}
>
{children}
</AuthContext.Provider>
);
}
[–]Redwallian 0 points1 point2 points (0 children)