firebase-handler
v1.0.0
Published
easy firebase handler
Downloads
2
Readme
@tomsd/firebase-handler
Installation
npm install @tomsd/firebase-handler
Usage
<script src="@tomsd/firebase-handler/dist/firebase-handler.js"></script>
import FirebaseHandler from "@tomsd/firebase-handler";
const fb_handler = new FirebaseHandler();
window.addEventListener("load", function(){fb_handler.ready(myproc);});
function myproc(){
const collection_name = "mycollection";
const db = fb_handler.easyStore(collection_name);
db.save({
data:"test"
}).then(function(){
db.get().then(function(docs){
console.log(docs);
});
});
db.get([{field:"data",operator:"==",value:"test"}]).then(function(docs){
if(docs.length === 0){return;}
db.remove(docs[0]._id).then(function(){
db.get().then(function(docs){
console.log(docs);
});
});
});
}
window.addEventListener("load", function(){fb_handler.ready(ensureLogin);});
function login(){
fb_handler.onAuthStateChanged(function(user){
if(user){
console.log(user);
}else{
fb_handler.login(fb_handler.getAuthProviderNames())
.then(function(){
console.log("logged in");
}, function(){
console.log("not logged in");
});
}
});
}
window.addEventListener("load", function(){fb_handler.ready(ensureLogin);});
function ensureLogin(){
fb_handler.onAuthStateChanged(function(user){
console.log(user);
});
fb_handler.ensureLogin(fb_handler.getAuthProviderNames());
}