2016-08-08 00:47:58 +05:30
|
|
|
/**
|
|
|
|
* Applies Bearer header for all requests
|
|
|
|
*
|
|
|
|
* @param {object} store - redux store
|
|
|
|
* @param {function} store.getState
|
|
|
|
*
|
|
|
|
* @return {object} - request middleware
|
|
|
|
*/
|
|
|
|
export default function bearerHeaderMiddleware({getState}) {
|
|
|
|
return {
|
2016-10-30 17:42:49 +05:30
|
|
|
before(req) {
|
|
|
|
let {token} = getState().user;
|
|
|
|
|
|
|
|
if (req.options.token) {
|
|
|
|
token = req.options.token;
|
|
|
|
}
|
2016-08-08 00:47:58 +05:30
|
|
|
|
|
|
|
if (token) {
|
2016-10-30 17:42:49 +05:30
|
|
|
req.options.headers.Authorization = `Bearer ${token}`;
|
2016-08-08 00:47:58 +05:30
|
|
|
}
|
|
|
|
|
2016-10-30 17:42:49 +05:30
|
|
|
return req;
|
2016-08-08 00:47:58 +05:30
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|