Guest User

Untitled

a guest
Mar 19th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. fetch('/wp-json/jwt-auth/v1/token', {
  2. headers: new Headers({
  3. 'Content-Type': 'application/x-www-form-urlencoded'
  4. }),
  5. method:'POST',
  6. body: 'username=yourname&password=yourpass'
  7. })
  8. .then(res => res.json())
  9. .then(json => {
  10. if(json.token) {
  11. localStorage.token = json.token
  12. } else {
  13. const error = new Error(json.message)
  14. error.code = json.code
  15. throw error
  16. }
  17. })
  18. .catch(reason => console.warn(reason))
Add Comment
Please, Sign In to add comment