Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

97
Vistas
how to authenticate with custom uid in firebase realtime database using javascript?

this is my realtime database

enter image description here

I use firebase realtime database, I use rules as below:

 {
  "rules": {
    "$uid": {
    ".read":"$uid === auth.uid",
    ".write": false
  }
}
}

when I use the playground rules as below it works, here I managed to read the 121212 data above.

enter image description here

This is my code snippet.

<script>
// Import the functions you need from the SDKs you need
    import {
        initializeApp
    } from "https://www.gstatic.com/firebasejs/9.6.11/firebase-app.js";
    import {
        getDatabase,
        ref,
        onValue,
    } from "https://www.gstatic.com/firebasejs/9.6.11/firebase-database.js";
    import {
        getAuth,
        signInWithCustomToken,
        createCustomToken
    } from "https://www.gstatic.com/firebasejs/9.6.11/firebase-auth.js";

    // TODO: Add SDKs for Firebase products that you want to use
    // https://firebase.google.com/docs/web/setup#available-libraries

    // Your web app's Firebase configuration
    // For Firebase JS SDK v7.20.0 and later, measurementId is optional
    const firebaseConfig = {
        apiKey: "",
        authDomain: "",
        databaseURL: "",
        projectId: "",
        storageBucket: "",
        messagingSenderId: "",
        appId: "",
        measurementId: ""
    };

    // Initialize Firebase
    const app = initializeApp(firebaseConfig);

</script>

The problem is, I want to read 121212 data via javascript.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

The auth.uid is UID of user logged in with Firebase Authentication in your web app requesting the data. First you'll have to sign them in:

import {
  getAuth,
  signInWithEmailAndPassword,
} from "https://www.gstatic.com/firebasejs/9.6.11/firebase-auth.js";

const app = initializeApp(firebaseConfig);
const auth = getAuth(app);

signInWithEmailAndPassword(auth, "user@domain.tld", "password").then((user) => {
  // read data using Firebase Realtime Database SDK
})

Firebase has recently posted many tutorials on their YouTube channel that would be useful:

  • Firebase Auth and Firestore - Javascript Crash Course
  • Getting Started with the Firebase Realtime Database on the Web
  • Getting started with Firebase Authentication on the web
about 4 years ago · Juan Pablo Isaza Denunciar

0

If you don't want the user to have to provide credentials, but still want then to only be able to access their own data, consider using Firebase's anonymous authentication where signing in is as easy as:

import { getAuth, signInAnonymously } from "firebase/auth";

const auth = getAuth();
await signInAnonymously(auth);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda