fix: logout bug
This commit is contained in:
		| @@ -111,7 +111,7 @@ async def get_current_user(security_scopes: SecurityScopes, request: Request): | ||||
|     except ExpiredSignatureError: | ||||
|         raise HTTPException( | ||||
|             status_code=status.HTTP_401_UNAUTHORIZED, | ||||
|             detail="Token expired", | ||||
|             detail="Access token expired", | ||||
|             headers={"WWW-Authenticate": authenticate_value}, | ||||
|         ) | ||||
|     except (InvalidTokenError, ValidationError): | ||||
| @@ -164,7 +164,7 @@ async def login_for_access_token( | ||||
|  | ||||
| async def logout(response: Response): | ||||
|     response.set_cookie("access_token", "", expires=0, httponly=True, samesite="strict") | ||||
|     return | ||||
|     return {"message": "Successfully logged out"} | ||||
|  | ||||
|  | ||||
| async def read_users_me( | ||||
|   | ||||
| @@ -1,6 +1,5 @@ | ||||
| import { MouseEventHandler, useEffect, useState } from "react"; | ||||
| import { useSession } from "./Session"; | ||||
| import { logout } from "./api"; | ||||
|  | ||||
| interface ContextMenuItem { | ||||
|   label: string; | ||||
| @@ -18,7 +17,7 @@ export default function Avatar() { | ||||
|   const contextMenuItems: ContextMenuItem[] = [ | ||||
|     { label: "View Profile", onClick: () => console.log("View Profile") }, | ||||
|     { label: "Edit Profile", onClick: () => console.log("Edit Profile") }, | ||||
|     { label: "Logout", onClick: onLogout }, | ||||
|     { label: "Logout", onClick: () => onLogout() }, | ||||
|   ]; | ||||
|  | ||||
|   const handleMenuClick: MouseEventHandler<HTMLDivElement> = (event) => { | ||||
|   | ||||
| @@ -1,10 +1,13 @@ | ||||
| import { useLocation } from "react-router"; | ||||
| import { Link } from "react-router"; | ||||
| import { useSession } from "./Session"; | ||||
|  | ||||
| export default function Footer() { | ||||
|   const location = useLocation(); | ||||
|   const { user } = useSession(); | ||||
|   return ( | ||||
|     <footer className={location.pathname === "/network" ? "fixed-footer" : ""}> | ||||
|       {user?.scopes.split(" ").includes("analysis") && ( | ||||
|         <div className="navbar"> | ||||
|           <Link to="/"> | ||||
|             <span>Form</span> | ||||
| @@ -18,6 +21,7 @@ export default function Footer() { | ||||
|             <span>MVP</span> | ||||
|           </Link> | ||||
|         </div> | ||||
|       )} | ||||
|       <p className="grey extra-margin"> | ||||
|         something not working? | ||||
|         <br /> | ||||
|   | ||||
| @@ -59,11 +59,9 @@ export function SessionProvider(props: SessionProviderProps) { | ||||
|       setUser(null); | ||||
|       setErr({ message: "Logged out successfully" }); | ||||
|       console.log("logged out."); | ||||
|       setLoading(true); // Set loading to true | ||||
|       loadUser(); | ||||
|     } catch (e) { | ||||
|       console.error(e); | ||||
|       setErr(e); // Update the error state if logout fails | ||||
|       setErr(e); | ||||
|     } | ||||
|   } | ||||
|   console.log("sanity", user); | ||||
| @@ -77,12 +75,7 @@ export function SessionProvider(props: SessionProviderProps) { | ||||
|       </> | ||||
|     ); | ||||
|   else if (err) { | ||||
|     if ((err as any).message === "Logged out successfully") { | ||||
|       setTimeout(() => setErr(null), 1000); | ||||
|     content = <Login onLogin={onLogin} />; | ||||
|     } else { | ||||
|       content = <Login onLogin={onLogin} />; | ||||
|     } | ||||
|   } else | ||||
|     content = ( | ||||
|       <sessionContext.Provider value={{ user, onLogout }}> | ||||
|   | ||||
| @@ -34,6 +34,7 @@ export type User = { | ||||
|   full_name: string; | ||||
|   email: string; | ||||
|   player_id: number; | ||||
|   scopes: string; | ||||
| }; | ||||
|  | ||||
| export async function currentUser(): Promise<User> { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user