Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

98
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda