Don't know what's the issue here.
If anyone know what's the issue here then please help me out.
I am trying to make anyonymous login.
Don't know what's the issue here.
If anyone know what's the issue here then please help me out.
I am trying to make anyonymous login.
const LoginManager = () => {
// Set an initializing state whilst Firebase connects
const [initializing, setInitializing] = useState(true);
const [user, setUser] = useGlobal('user');
// Handle user state changes
function onAuthStateChanged(user) {
setUser(user);
if (initializing) {
setInitializing(false);
}
}
useEffect(() => {
const subscriber = auth().onAuthStateChanged(onAuthStateChanged);
return subscriber; // unsubscribe on unmount
// eslint-disable-next-line react-hooks/exhaustive-deps
if (initializing) {
return null;
}
if (!user) {
return auth()
.signInAnonymously()
.then(() => {
console.log('User signed in anonymously');
})
.catch((error) => {
if (error.code === 'auth/operation-not-allowed') {
console.log('Enable anonymous in your firebase console.');
}
console.log(error);
});
} else {
console.log('User already signed in.');
}
}, []);
return null;
};