- 
      
- 
        Save croogie/d6eaeaa948031a2a2c3b3e40970d957e to your computer and use it in GitHub Desktop. 
    axios: interceptor which includes your oauth token in every request as an Authorization header
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import axios from 'axios'; | |
| // You can use any cookie library or whatever | |
| // library to access your client storage. | |
| import cookie from 'cookie-machine'; | |
| axios.interceptors.request.use(function(config) { | |
| const token = cookie.get(__TOKEN_KEY__); | |
| if ( token != null ) { | |
| config.headers.Authorization = `Bearer ${token}`; | |
| } | |
| return config; | |
| }, function(err) { | |
| return Promise.reject(err); | |
| }); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment