hopper
hopper

Reputation: 4348

Can I integrate with firebase in a secure way without having user authentication without having server side code?

My site is just one page with a form. I don't have any user auth functionality . Can I still use client side firebase integration without passing through a server side code in a secure way? If yes how can I secure the details for my firebase connection ?

Upvotes: 6

Views: 2703

Answers (2)

fiatjaf
fiatjaf

Reputation: 12177

Yes.

Just add these tags to you page:

<script type="text/javascript" src="https://cdn.firebase.com/v0/firebase.js"></script>
<script type="text/javascript" src="https://cdn.firebase.com/v0/firebase-simple-login.js"></script>

Then write this code:

var chatRef = new Firebase('https://YOUR-APP.firebaseIO.com');
var auth = new FirebaseSimpleLogin(chatRef, function(error, user) {
  if (error) {
    // an error occurred while attempting login
    console.log(error);
  } else if (user) {
    // user authenticated with Firebase
    console.log('User ID: ' + user.id + ', Provider: ' + user.provider);
  } else {
    // user is logged out
  }
});

And when your user clicks the login button, call

// attempt to log the user in with your preferred authentication provider
auth.login('github (or twitter, or what you want)');

As explained here and demonstrated here.

Upvotes: 2

Anant
Anant

Reputation: 7428

You can use the new anonymous auth functionality provided by Firebase Simple Login: https://www.firebase.com/docs/security/simple-login-anonymous.html

With this mechanism, you can have users of your website authenticate to Firebase anonymously (they don't need to enter any login credentials), but you can still protect reads and writes to your Firebase using regular security rules.

Upvotes: 6

Related Questions