Adds WP cookie authentication to your WP Gatsby site to keep you authenticated in WP and your frontend at the same time. Automatically creates a /login
and /dashboard
page to manage your content.
You can also import the custom useAuth
hook anywhere in your application. It will return your user.
yarn add gatsby-theme-headless-wordpress-admin
Example usage
import { useAuth } from "gatsby-theme-headless-wordpress-admin";
const { auth } = useAuth();
Example usage
import { useLogin } from "gatsby-theme-headless-wordpress-admin";
const [sendUserLogin, { data, error, loading, called }] = useLogin({
onCompleted: (data) => {
console.log({ data });
},
onError: (err) => {
console.log({ err });
},
});
<button
onClick={() =>
sendUserLogin({
variables: { username: "your_username", password: "your_password" },
})
}
/>;