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

StackOverflow https://stackoverflow.com/questions/19293733

  •  30-06-2022
  •  | 
  •  

Pregunta

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 ?

¿Fue útil?

Solución

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.

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top