Wordpress JWT Auth
JS Wrapper for wp-api-jwt-auth
Installation
Please, make sure that you have:
- installed wp-api-jwt-auth and enabled on your wp site
- enabled HTTP Authorization Header
- configurated Secret Key and CORs Support
install this package:
npm install wordpress-jwt-auth
Example
connectToJwt(host)
Authenticate using JWT
; // Promise; // Await/Asyncconst jwtConnection = await ;const token = await jwtConnection;console;// true
generateToken(username, password)
You can import generateToken
directly from library
; const token = ;
Real use
Deleting a post with id 32
from wordpress using REST API
;; const WP_URL = 'https://www.mywordpress.com';const POST_ID_TO_DELETE = 32; const generateToken = await ;const token = await ;const authHeader = headers: Authorization: `bearer ` ; axios;