firebase - how to persist data throughout all pages in the application? -


hi developing cross platform application. have register page user details user email , password , other details. save data under particular user. create child unique email id given user , remaining details must stored under userenter image description here need above product data , service data stored inside first user. path must user logged in application. should take data pages. how can please me? here code how create above structure inside database.

$(".subscribe1").click(function(){     var t1 = document.getelementbyid("email").value;     var t2 = document.getelementbyid("password").value;     var t3 = document.getelementbyid("confirmpassword").value;     var companyname = document.getelementbyid("companyname").value;         var address = document.getelementbyid("address").value;         var city = document.getelementbyid("city").value;         var pincode = document.getelementbyid("pincode").value;         var country = document.getelementbyid("country").value;         var sname = document.getelementbyid("sname").value;         var sid = document.getelementbyid("sid").value;         var saddr = document.getelementbyid("saddr").value;         var scity = document.getelementbyid("scity").value;         var spincode = document.getelementbyid("spincode").value;         var scountry = document.getelementbyid("scountry").value;         var s;         s = (t1.replace('.', ',')); console.log(s);         var ref = new firebase("https://sampleapp.firebaseio.com/");         var account = ref.child(s+"/master_account");         account.push({"email": t1 , "password": t2});         var cmp = ref.child(s+"/company_details");         cmp.push({"email": t1, "company_name": companyname , "address": address, "city": city, "pincode": pincode, "country": country});        var store = ref.child(s+"/store_location");         store.push({"email": t1, "store_name": sname , "store_id" :sid , "address": saddr, "city": scity, "pincode": spincode, "country": scountry}); }); 

to clear on point, want logged in user's data available across app.

here possible measures take achieving that.

  • once user logged in.
    • save basic data localstorage, cache or sessionstore (data such first_name, last_name, email).
    • then other pages, can query firebase load other data need page.

ref.child(email).child('master_account').once('value', () => {}); once data, save somewhere in variable object if want use page alone or cache or localstorage or session-store if want use across other pages.

if user logs out, you'd clear cache,local-storage or session-store whichever choose save data in. , you'd check see if user's detail still exists in of otherwise you'd log them out.

-i hope helps.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -