I've been trying to make a util method which will return either the user object or if the user object exists. With no params it should return a boolean and with the param "getUser" it should return the user object, but it is always returning undefined. This seemed to work for a while, but then I took a break and came back and it was always returning undefined. Code below
import { getAuth, onAuthStateChanged } from "firebase/auth";
export default function checkAuthState(type?:string){
const auth = getAuth()
onAuthStateChanged(auth, (user) => {
if (user) {
if(!type) return true
if(type === "getUser") return user
else return true
} else {
if(!type) return false
else return false
}
});
}