Hướng dẫn lấy REFRESH_TOKEN REFRESH TOKEN (ok)

{
"data": {
"login": {
"refreshToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3dwY2xpZGVtby5kZXYiLCJpYXQiOjE3Mzk5OTU4MjgsIm5iZiI6MTczOTk5NTgyOCwiZXhwIjoxNzcxNTMxODI4LCJkYXRhIjp7InVzZXIiOnsiaWQiOiIxIiwidXNlcl9zZWNyZXQiOiJncmFwaHFsX2p3dF82N2I0ZTM1ZDhiODQyIn19fQ.FwrXtFD2flxFNEwDveyhByXJc7s5nL875QAz55P3TbM"
}
},
"extensions": {
"debug": [],
"queryAnalyzer": {
"keys": "0b4cac0b0ab05df9c0bc564b4c73733ee92ad77c55bccb533114bc0a3295f90d graphql:Mutation operation:Login",
"keysLength": 97,
"keysCount": 3,
"skippedKeys": "",
"skippedKeysSize": 0,
"skippedKeysCount": 0,
"skippedTypes": []
}
}
}README.md
Next.js + WordPress
It's headless WordPress! 💀 - https://nextjswp.com This is a bare-bones Next.js app, which fetches data from WordPress via WPGraphQL and styles it with TailwindCSS. Please consider it a starting point for your next headless WordPress project.
Supported Features
Category and Tag Archives
Comments
Custom Fields
Custom Post Types
On-demand Revalidation
Post/Page Previews
RSS Feed
Robots.txt
Search
Sitemap.xml
Static Site Generation (SSG)
TypeScript, ESLint, and Prettier
WordPress Menus
Yoast SEO Plus it's really, really fast! 🚀

Setup
1. Clone the repo
2. Install dependencies
3. Create a .env.local file
.env.local fileCustomize the URLs in .env.local to match your WordPress setup:
4. Configure next.config.js
next.config.jsUpdate the URL in next.config.js to match your WordPress site:
5. Configure /lib/config.ts
/lib/config.tsOpen /lib/config.ts and update the content to match your WordPress site:
6. Configure WordPress
Plugins
You'll need either a local or public WordPress site with the following plugins:
Advanced Custom Fields (free version is fine)
WPGraphQL JWT Authentication (optional)
WP-Config
After installing all the plugins mentioned above, you'll need to add some constants to your wp-config.php file:
Permalinks
Finally, set your permalink structure to /blog/%postname%/ in Settings -> Permalinks.
7. Optional. Authentication for Previews
In order to query draft posts for Previews, you'll need to authenticate with WordPress. The following is a one-time step:
Install and activate the WPGraphQL JWT Authentication plugin
Generate any random string. I recommend using the WordPress salt generator
Copy the string
Open your
wp-config.phpfile, and paste the string into theGRAPHQL_JWT_AUTH_SECRET_KEYconstant
Go to GraphQL -> GraphiQL IDE in your WordPress admin
Copy the following and paste into GraphiQL IDE (replace
your_usernameandyour_passwordwith your WordPress credentials)
Click the Play button in GraphiQL to run the mutation
Copy the
refreshTokenreturned by the mutationOpen the Next.js
.env.localfile, and paste therefreshTokeninto theNEXTJS_AUTH_REFRESH_TOKENvariable
You should now be able to preview draft posts in your Next.js app by clicking the Preview button in your WordPress admin.
8. Start the dev server
Once the dev server has started, you can view the front-end: http://localhost:3000
Querying WordPress data with GraphQL
GraphQL is efficient because we can query multiple endpoints in a single request. If we were to use the WordPress REST-API, we would need to make multiple round trips to each respective endpoint. We can build our queries in GraphiQL (or your favorite REST client) and let JSON.stringify() format it. Because this is all standard JavaScript, we can even pass variables to our queries-- no need for a 3rd party package! Here is a query to fetch a single post (based on the slug), the featured image, author meta, categories, tags, SEO, and post comments:
This repo does not use a 3rd party GraphQL package, because Next.js automatically memoizes the fetch() requests in our custom fetch function. This means that if we fetch the same data twice, Next.js will only make one request to WordPress.
If you prefer use a 3rd party GraphQL package, simply swap out the custom
fetchGraphQL()function with the package of your choosing.
Going To Production
Other
RSS Feed, Sitemap, Robots.txt
Previews
Contributing
This is a hobby project and my time is limited, so your contributions are welcome! Please see the contributing guidelines to get started.
Last updated
Was this helpful?