Advertisement
Guest User

Untitled

a guest
Jan 11th, 2018
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const User = {
  2.     getPassword() {
  3.         return new Promise(resolve => {
  4.             setTimeout(resolve, 100, "foo");
  5.         });
  6.     }
  7. };
  8. const userInfoURL = "/";
  9. class Example {
  10.     static async login() {
  11.         let password = await User.getPassword();
  12.         alert(password); // this works, password is shown
  13.         return fetch(userInfoURL, {
  14.             method: 'GET',
  15.             headers: {
  16.                 'Authorization': password,
  17.                 'Content-Type': 'application/json'
  18.             }
  19.         })
  20.     }
  21. }
  22. Example.login()
  23.     .then(response => response.json())
  24.     .then(data => { console.log("worked", data); })
  25.     .catch(err => { console.error("failed", err); });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement