POST to the logout endpoint when logging out
All checks were successful
Deploy / deploy (ubuntu-latest, 2.44.0) (push) Successful in 2m0s
All checks were successful
Deploy / deploy (ubuntu-latest, 2.44.0) (push) Successful in 2m0s
This commit is contained in:
parent
63166d4e45
commit
1facd632d4
@ -24,6 +24,8 @@ import Link from "next/link";
|
|||||||
import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime";
|
import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { Cookies, useCookies } from "next-client-cookies";
|
import { Cookies, useCookies } from "next-client-cookies";
|
||||||
|
import { Session } from "@/app/types/user/session";
|
||||||
|
import { apiRequest } from "@/lib/api";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The menu to manage the user.
|
* The menu to manage the user.
|
||||||
@ -31,6 +33,9 @@ import { Cookies, useCookies } from "next-client-cookies";
|
|||||||
* @return the menu jsx
|
* @return the menu jsx
|
||||||
*/
|
*/
|
||||||
const UserMenu = (): ReactElement => {
|
const UserMenu = (): ReactElement => {
|
||||||
|
const session: Session | undefined = useUserContext(
|
||||||
|
(state: UserState) => state.session
|
||||||
|
);
|
||||||
const user: User | undefined = useUserContext(
|
const user: User | undefined = useUserContext(
|
||||||
(state: UserState) => state.user
|
(state: UserState) => state.user
|
||||||
);
|
);
|
||||||
@ -40,7 +45,12 @@ const UserMenu = (): ReactElement => {
|
|||||||
/**
|
/**
|
||||||
* Logout the user.
|
* Logout the user.
|
||||||
*/
|
*/
|
||||||
const logout = () => {
|
const logout = async () => {
|
||||||
|
await apiRequest<void>({
|
||||||
|
endpoint: "/user/logout",
|
||||||
|
method: "POST",
|
||||||
|
session,
|
||||||
|
});
|
||||||
cookies.remove("session");
|
cookies.remove("session");
|
||||||
router.push("/");
|
router.push("/");
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user