aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKumar Priyansh <[email protected]>2019-06-03 06:13:20 +0530
committerKumar Priyansh <[email protected]>2019-06-03 06:13:20 +0530
commit7b8b70eb20a23600da5d6082927d3b9aa4d7c8c0 (patch)
treeeb873e20feac3d44691e049ffad89a10d9749956
parentcf73b2764c8c593de704edcf015186f43874c0e7 (diff)
downloadfirebase-ecommerce-7b8b70eb20a23600da5d6082927d3b9aa4d7c8c0.tar.xz
firebase-ecommerce-7b8b70eb20a23600da5d6082927d3b9aa4d7c8c0.zip
Added Signout function and Auto Redirect for Non Authenicated users
-rw-r--r--shared/cart.js26
1 files changed, 25 insertions, 1 deletions
diff --git a/shared/cart.js b/shared/cart.js
index 54fa736..bc8f509 100644
--- a/shared/cart.js
+++ b/shared/cart.js
@@ -1,3 +1,27 @@
$(document).ready(function(){
-
+ $('#cart').click(function(){
+ window.location.replace('../')
+ })
+ function showAlert(message) {
+ // Get the snackbar DIV
+ var x = document.getElementById("snackbar");
+ $('#snackbar').text(message)
+ // Add the "show" class to DIV
+ x.className = "show";
+
+ // After 3 seconds, remove the show class from DIV
+ setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
+ }
+ $('#signout').click(function(){
+ firebase.auth().signOut().then(function() {
+ window.location.replace('../')
+ }).catch(function(error) {
+ showAlert("Failed to sign out")
+ });
+ })
+ firebase.auth().onAuthStateChanged(function(user) {
+ if (!user) {
+ window.location.replace('../')
+ }
+ });
}) \ No newline at end of file