Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. const ServiceApi = axios.create({
  2. baseURL: BASE_URL,
  3. responseType: 'json'
  4. });
  5.  
  6. return {
  7. type: PERFORM_LOGIN,
  8. payload: {
  9. user: {
  10. name: username
  11. },
  12. request: {
  13. url: '/login',
  14. method: 'post',
  15. headers: {
  16. 'Authorization': 'Basic ' + basicAuth
  17. }
  18. }
  19. }
  20.  
  21. // On login success, set the authInterceptor responsible for adding headers
  22. authInterceptor = ServiceApi.interceptors.request.use((config) => {
  23. console.log(`Attaching Authorization to header ${basicAuth}`);
  24. config.headers.common.Authorization = basicAuth;
  25. return config;
  26. }, (error) => {
  27. Promise.reject(error);
  28. });
  29.  
  30. // Clear the auth interceptor
  31. ServiceApi.interceptors.request.eject(authInterceptor);
  32.  
  33. _headers:
  34. accept: "application/json, text/plain, */*"

  35. authorization: "Basic <correct base64 value>"

  36. content-type: "application/json;charset=utf-8"
__proto__: Object

  37.  
  38. _headers:
  39. accept: (...)

  40. authorization: (...)

  41. content-type: (...)

  42. get accept: ƒ ()
  43. 
set accept: ƒ ()

  44. get authorization: ƒ ()
  45. 
set authorization: ƒ ()
  46. 
get content-type: ƒ ()

  47. set content-type: ƒ ()

  48. __proto__: Object

Advertisement
Add Comment
Please, Sign In to add comment
Advertisement