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

My site is just one page with a form. I do not have custom functions. Can I use client-side firebase integration without secure access to the server code? If so, how can I protect the data to connect to firebase?

+6
source share
2 answers

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

Using this mechanism, you can anonymously register users of your site on Firebase (they do not need to enter login credentials), but you can still protect reads and writes in your Firebase using normal security rules.

+6
source

Yes.

Just add these tags to the 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 described here and demonstrated here .

+2
source

Source: https://habr.com/ru/post/955658/


All Articles