LoginSignup
1
0

More than 5 years have passed since last update.

Firebase Realtime Database をブラウザから使う

Posted at

実装

<script src="https://www.gstatic.com/firebasejs/4.12.1/firebase.js"></script>
<script>
    let config = {
        apiKey: "xxxxx",
        authDomain: "xxxxx.firebaseapp.com",
        databaseURL: "https://xxxxx-xxxxx.firebaseio.com",
        projectId: "xxxxx",
        storageBucket: "xxxxx.appspot.com",
        messagingSenderId: "xxxxx"
    };
    firebase.initializeApp(config);
    let abcRef = firebase.database().ref('abc');
    abcRef.on('child_added', function(data) {
        console.log('child_added', data.val());
    });
</script>

注意点

  • コンフィグ部分は Firebase の管理コンソールの「ウェブアプリにFirebaseを追加」リンクからコピーする。
  • 上記のconfigはただの接続情報なのでgitに入れてよいが、認証を設けていないなら一般への流出は避けなければならない。(誰でもアクセスできるので最悪、すごい課金が発生することになる。)
  • databaseURL はデフォルトのものを使わず、作成したほうがセキュア(URLが予想しにくくなるので)。
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0