Skip to content

Instantly share code, notes, and snippets.

@basetdd2416
Forked from srph/oauth.js
Created February 5, 2019 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save basetdd2416/6b3ca4a49a55a7547f7a2db61cfc015d to your computer and use it in GitHub Desktop.
Save basetdd2416/6b3ca4a49a55a7547f7a2db61cfc015d to your computer and use it in GitHub Desktop.
axios: interceptor which includes your oauth token in every request as an Authorization header
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