Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fetch('/wp-json/jwt-auth/v1/token', {
- headers: new Headers({
- 'Content-Type': 'application/x-www-form-urlencoded'
- }),
- method:'POST',
- body: 'username=yourname&password=yourpass'
- })
- .then(res => res.json())
- .then(json => {
- if(json.token) {
- localStorage.token = json.token
- } else {
- const error = new Error(json.message)
- error.code = json.code
- throw error
- }
- })
- .catch(reason => console.warn(reason))
Add Comment
Please, Sign In to add comment