@@ -8,6 +8,7 @@ import { toast } from 'react-toastify';
88import { auth , provider } from "./firebase/FirebaseConfig" ;
99import { signInWithPopup } from "firebase/auth" ;
1010import { handleCreateUserWithEmailAndPassword , handleSignInWithEmailAndPassword } from './firebase/LoginAuthCreation' ;
11+ import ClipLoader from 'react-spinners/ClipLoader' ;
1112
1213// for each time show the google accounts in the dialog
1314provider . setCustomParameters ( {
@@ -22,6 +23,7 @@ function LoginPage(props) {
2223 //for navigate
2324 const navigateToNextPage = useNavigate ( ) ;
2425 const { setLoggedInUser} = props ;
26+ const [ isLoading , setIsLoading ] = useState ( false ) ;
2527 const [ isRegisterClicked , setRegisterClicked ] = useState ( false ) ;
2628
2729 //password requirement
@@ -101,9 +103,11 @@ function LoginPage(props) {
101103 if ( ! isValidated ) return ;
102104
103105 try {
106+ setIsLoading ( true ) ;
104107 const signInwithUsername = await handleSignInWithEmailAndPassword ( input . username , input . password ) ;
105108 if ( signInwithUsername ?. success ) {
106109 const userObj = {
110+ loginUsernamePwdSuccess : signInwithUsername ?. success ,
107111 displayName : input . username . slice ( 0 , 7 ) + "..." ,
108112 email : input . username
109113 }
@@ -118,6 +122,7 @@ function LoginPage(props) {
118122 } catch ( e ) {
119123 console . log ( "catch error login--" , e )
120124 } finally {
125+ setIsLoading ( false ) ;
121126 }
122127 }
123128
@@ -134,6 +139,7 @@ function LoginPage(props) {
134139 }
135140
136141 try {
142+ setIsLoading ( true ) ;
137143 const registerWithUsername = await handleCreateUserWithEmailAndPassword ( input . username , input . password ) ;
138144 if ( registerWithUsername ?. success ) {
139145 notifyToast ( {
@@ -146,6 +152,8 @@ function LoginPage(props) {
146152 navigateToRegister_Login ( ) ;
147153 } catch ( e ) {
148154 console . log ( "catch error register--" , e )
155+ } finally {
156+ setIsLoading ( false ) ;
149157 }
150158 }
151159
@@ -188,6 +196,7 @@ function LoginPage(props) {
188196 const storeLoginSuccessAndNavigate = ( user ) => {
189197 const loginObj = {
190198 loginSuccess : true ,
199+ loggedInType : user ?. loginUsernamePwdSuccess ? "usernamePwd" : "socialLogin" ,
191200 loggedInUsername : user ?. displayName || "" ,
192201 loggedInEmail : user ?. email || input ?. username || "" ,
193202 loggedInPhotoUrl : user ?. photoURL || ""
@@ -266,6 +275,11 @@ function LoginPage(props) {
266275
267276 { /* Password hint feedback dialog */ }
268277 { isPwdFeedbackHint }
278+
279+ { /* Loader */ }
280+ { isLoading && < div className = "loader" >
281+ < ClipLoader color = "#09f" loading = { isLoading } size = { 50 } /> </ div >
282+ }
269283 </ div >
270284
271285 )
0 commit comments