Skip to main content
DocsReferenceuseLogout

useLogout

useLogout is a React hook that facilitates logging out from your Faust app.

API

The useLogout exports look like this defined as a TypeScript type:

type UseLogout = {
	loading: boolean;
	error: Response | undefined;
	logout: (redirectUrl?: string) => void;
};

Here is a description of each:

  • loading: If true, the request is still in flight.
  • error: If the logout process produces one or more errors, this object contains either an array of graphQLErrors or a single networkError. Otherwise, this value is undefined.
  • logout: Callback function to initiate the logout request. You can pass an optional redirectUrl parameter that is used to redirect once you successfully complete the process.

Usage

Below is an example of displaying a logout button, and upon successful logout, redirecting the user back to the homepage:

import { useLogout } from "@faustwp/core";
 
export function AuthenticatedView() {
	const { logout } = useLogout();
 
	return (
		<>
			<button onClick={() => logout("/")}>Logout</button>
		</>
	);
}