11<template >
22 <div >
3- <router-view :isAuthenticated =" isAuthenticated" :handleAuth =" handleAuth" />
3+ <div v-if =" loading" class =" loader p-4" >
4+ <div ></div >
5+ </div >
6+ <router-view
7+ :createAlert =" createAlert"
8+ :clearAlerts =" clearAlerts"
9+ :alerts =" alerts"
10+ :isAuthenticated =" isAuthenticated"
11+ :handleAuth =" handleAuth"
12+ />
413 </div >
514</template >
615
@@ -11,8 +20,22 @@ export default {
1120 data () {
1221 return {
1322 isAuthenticated: false ,
23+ loading: true ,
24+ alerts: null ,
1425 };
1526 },
27+ watch: {
28+ alerts () {
29+ const vm = this ;
30+ if (vm .alerts !== " " ) {
31+ setTimeout (() => {
32+ vm .alerts = " " ;
33+ }, 4000 );
34+ } else {
35+ clearTimeout ();
36+ }
37+ },
38+ },
1639 beforeCreate : async function () {
1740 const vm = this ;
1841 await firebase .auth ().onAuthStateChanged (function (user ) {
@@ -21,9 +44,16 @@ export default {
2144 } else {
2245 console .log (" User is not authenticated" );
2346 }
47+ vm .loading = false ;
2448 });
2549 },
2650 methods: {
51+ createAlert (ev ) {
52+ this .alerts = { ... ev };
53+ },
54+ clearAlerts () {
55+ this .alerts = null ;
56+ },
2757 handleAuth : async function (ev ) {
2858 const vm = this ;
2959 if (ev .mode === " login" ) {
@@ -33,7 +63,7 @@ export default {
3363 .signInWithEmailAndPassword (ev .email , ev .password );
3464 vm .isAuthenticated = true ;
3565 } catch (e) {
36- return e . message ;
66+ return e;
3767 }
3868 } else if (ev .mode === " register" ) {
3969 try {
@@ -42,12 +72,16 @@ export default {
4272 .createUserWithEmailAndPassword (ev .email , ev .password );
4373 vm .isAuthenticated = true ;
4474 } catch (e) {
45- return e . message ;
75+ return e;
4676 }
4777 } else {
4878 try {
4979 await firebase .auth ().signOut ();
5080 vm .isAuthenticated = false ;
81+ this .alerts = {
82+ code: " Notification" ,
83+ message: " Successfully Signed out" ,
84+ };
5185 } catch (e) {
5286 return e;
5387 }
@@ -58,4 +92,31 @@ export default {
5892 </script >
5993
6094<style >
95+ .loader {
96+ height : 100vh ;
97+ width : 100vw ;
98+ position : absolute ;
99+ z-index : 99 ;
100+ display : flex ;
101+ align-items : center ;
102+ background : rgb (31 , 29 , 29 );
103+ }
104+ .loader div {
105+ height : 100px ;
106+ width : 100px ;
107+ border : 3px solid rgb (241 , 211 , 211 );
108+ border-bottom : 0 ;
109+ border-top : 0 ;
110+ border-radius : 50% ;
111+ margin : auto ;
112+ animation : loader 1s infinite linear ;
113+ }
114+ @keyframes loader {
115+ from {
116+ transform : rotate (0deg );
117+ }
118+ to {
119+ transform : rotate (360deg );
120+ }
121+ }
61122 </style >
0 commit comments