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