Community Plugin
View plugin on GitHubGatsby Wordpress Admin
What does it do?
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.
Getting Started
yarn add gatsby-theme-headless-wordpress-admin
Required WP plugins
useAuth
Example usage
import { useAuth } from "gatsby-theme-headless-wordpress-admin";
const { auth } = useAuth();useLogin
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" },
})
}
/>;