11import { MdEmail } from "react-icons/md" ;
22import { RiLockPasswordFill } from "react-icons/ri" ;
3- import { AiTwotoneHome } from 'react-icons/ai' ;
43import React , { useState , useEffect } from "react" ;
54import { useRouter } from "next/router" ;
65import { useUser } from "../lib/hooks" ;
@@ -10,13 +9,14 @@ export default function Login() {
109 const router = useRouter ( ) ;
1110 const [ errorMsg , setErrorMsg ] = useState ( "" ) ;
1211 const [ user , { mutate } ] = useUser ( ) ;
12+ const [ loading , isLoading ] = useState ( user ?true :false ) ;
1313 useEffect ( ( ) => {
1414 // redirect to home if user is authenticated
1515 if ( user ) router . replace ( "/" ) ;
1616 } , [ user ] ) ;
1717
1818 async function onSubmit ( e ) {
19-
19+ isLoading ( true ) ;
2020 e . preventDefault ( ) ;
2121 const body = {
2222 email : e . currentTarget . email . value ,
@@ -32,12 +32,16 @@ export default function Login() {
3232 mutate ( userObj ) ;
3333 M . toast ( { html : 'Logged in' , classes : 'blue' } )
3434 } else {
35+ isLoading ( false ) ;
3536 setErrorMsg ( "Incorrect username or password. Try again!" ) ;
3637 }
3738 }
3839
3940 return (
4041 < >
42+ { loading ?< div class = "progress" >
43+ < div class = "indeterminate" > </ div >
44+ </ div > :null }
4145 < div className = "row" >
4246 < div className = "col s12 m12" >
4347 < div className = "card z-depth-0" >
0 commit comments