Как из firebase вытащить всех юзеров списком?

Есть список юзеров которые регистрируются по форме авторизации
630fb5f03dc6e132017449.png
как вытащить весь список юзеров, например все email которые были занесены в эту бд ?
  • Вопрос задан
  • 359 просмотров
Решения вопроса 1
@Wyse Автор вопроса
Первое что хочу сделать, это переделать из модульного подключения в импорты
Делаю все по доке
Выдает ошибку applicationDefault is not defined
import { initializeApp } from 'firebase/app';
import { getDatabase, set, ref, update } from "firebase/database";
import { getAuth, createUserWithEmailAndPassword, signInWithEmailAndPassword, onAuthStateChanged, signOut } from "firebase/auth";
import { firebaseConfig} from './firebase/firebaseConfig.js';

initializeApp({
   credential: applicationDefault(),
   databaseURL: 'https://auth-examplec-default-rtdb.firebaseio.com'
});



 export const app = initializeApp(firebaseConfig);
 export const database = getDatabase(app);
 export const auth = getAuth();

 export const signUp = document.getElementById('signUp');
 export const login = document.getElementById('login');
 export const logout = document.getElementById('logout');
 export const goSignUp = document.querySelector('.goSignUp');
 export const goSignIn = document.querySelector('.goSignIn');
 export let loggedTitle = document.querySelector('.loggedTitle');
 goSignUp.style.display = 'none';
 logout.style.display = 'none';
 login.style.display = 'none';
 loggedTitle.style.display = 'none';

//* юзер зарегистрировался
function accountIsRegistred() {
	signUp.style.display = 'none';
	goSignIn.style.display = 'none';
	login.style.display = 'block';
	goSignUp.style.display = 'block';
}

//* юзер авторизировался
function logged(){
	let email = document.querySelector('.sign-form__email');
	let password = document.querySelector('.sign-form__password');
	login.style.display = 'none';
	goSignUp.style.display = 'none';
	logout.style.display = 'block';
	email.style.display = 'none';
	password.style.display = 'none';
	loggedTitle.style.display = 'block';
}

//* переход к регистрации
function registration(){
	goSignUp.style.display = 'none';
	logout.style.display = 'none';
	login.style.display = 'none';
	signUp.style.display = 'block';
	goSignIn.style.display = 'block';
}

//* переход к авторизации
function goLogin() {
	accountIsRegistred();
	logout.style.display = 'none';

}


goSignIn.addEventListener('click', (e) => {
	accountIsRegistred(signUp)
	goSignIn.style.display = "none";
})

goSignUp.addEventListener('click', (e) => {
	registration();
})

signUp.addEventListener('click', (e) => {
		let email = document.getElementById('email').value;
		let password = document.getElementById('password').value;
		// let username = document.getElementById('username').value;

createUserWithEmailAndPassword(auth, email, password)
  .then((userCredential) => {
    const user = userCredential.user;

	 set(ref(database, 'users/' + user.uid),{
		// username: username,
		email: email,
		password: password,
	 })
	 alert("user created " + email);
	 accountIsRegistred();
  })
  .catch((error) => {
    const errorCode = error.code;
    const errorMessage = error.message;
    
	 alert(errorMessage);
  });
	})

login.addEventListener('click', (e) => {
		let email = document.getElementById('email').value;
		let password = document.getElementById('password').value;
signInWithEmailAndPassword(auth, email, password)
  .then((userCredential) => {
    const user = userCredential.user;

	 const dt = new Date();

	 update(ref(database, 'users/' + user.uid),{
		last_login: dt
	 })

	 alert('User loged in! ' + email);
	 logged();
	 loggedTitle.innerHTML =" You are logged as " + email;
  })
  .catch((error) => {
    const errorCode = error.code;
    const errorMessage = error.message;

	 alert(errorMessage);

  });

});


const user = auth.currentUser;
onAuthStateChanged(auth, (user) => {

if (user) {
  // User is signed in, see docs for a list of available properties
  // https://firebase.google.com/docs/reference/js/firebase.User
  const uid = user.uid;

  // ...
} else {
  // No user is signed in.
}
});


logout.addEventListener('click', (e) => {
	
	signOut(auth).then(() => {
  // Sign-out successful.
  alert('user loged out');
	goLogin();
}).catch((error) => {
	const errorCode = error.code;
    const errorMessage = error.message;

	 alert(errorMessage);
});
});
Ответ написан
Пригласить эксперта
Ответы на вопрос 2
ddv88
@ddv88
Binance Futures
Зарегайся в OneSignal и юзай их API. Проще некуда.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы