@@ -15,7 +15,7 @@ const Navbar: React.FC = () => {
1515 if ( ! themeContext || ! authContext ) return null ;
1616
1717 const { toggleTheme, mode } = themeContext ;
18- const { isAuthenticated, logout } = authContext ;
18+ const { isAuthenticated, isLoading , logout } = authContext ;
1919
2020 const navLinkStyles = ( { isActive } : { isActive : boolean } ) =>
2121 `px-4 py-2 rounded-xl text-sm lg:text-base font-semibold transition-all duration-300 ${
@@ -27,9 +27,14 @@ const Navbar: React.FC = () => {
2727 const closeMenu = ( ) => setIsOpen ( false ) ;
2828
2929 const handleLogout = async ( ) => {
30- await logout ( ) ;
31- closeMenu ( ) ;
32- navigate ( "/login" , { replace : true } ) ;
30+ try {
31+ await logout ( ) ;
32+ navigate ( "/login" , { replace : true } ) ;
33+ } catch {
34+ // optionally surface a toast/message
35+ } finally {
36+ closeMenu ( ) ;
37+ }
3338 } ;
3439
3540 return (
@@ -64,7 +69,7 @@ const Navbar: React.FC = () => {
6469 Contributors
6570 </ NavLink >
6671
67- { ! isAuthenticated && (
72+ { ! isLoading && ! isAuthenticated && (
6873 < >
6974 < NavLink to = "/login" className = { navLinkStyles } >
7075 Login
@@ -76,7 +81,7 @@ const Navbar: React.FC = () => {
7681 </ >
7782 ) }
7883
79- { isAuthenticated && (
84+ { ! isLoading && isAuthenticated && (
8085 < button
8186 onClick = { handleLogout }
8287 className = "px-4 py-2 rounded-xl text-sm lg:text-base font-semibold transition-all duration-300 text-white bg-rose-500 hover:bg-rose-600 shadow-sm"
@@ -159,7 +164,7 @@ const Navbar: React.FC = () => {
159164 Contributors
160165 </ NavLink >
161166
162- { ! isAuthenticated && (
167+ { ! isLoading && ! isAuthenticated && (
163168 < >
164169 < NavLink
165170 to = "/login"
@@ -179,7 +184,7 @@ const Navbar: React.FC = () => {
179184 </ >
180185 ) }
181186
182- { isAuthenticated && (
187+ { ! isLoading && isAuthenticated && (
183188 < button
184189 onClick = { handleLogout }
185190 className = "text-left px-4 py-2 rounded-xl text-sm lg:text-base font-semibold transition-all duration-300 text-white bg-rose-500 hover:bg-rose-600 shadow-sm"
0 commit comments