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
: Iftrue
, the request is still in flight.error
: If the logout process produces one or more errors, this object contains either an array ofgraphQLErrors
or a singlenetworkError
. Otherwise, this value isundefined
.logout
: Callback function to initiate the logout request. You can pass an optionalredirectUrl
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>
</>
);
}