nfp_sites/app/api/common.js

21 lines
523 B
JavaScript
Raw Normal View History

2019-02-22 14:53:43 +00:00
const m = require('mithril')
const Authentication = require('../authentication')
exports.sendRequest = function(options) {
let token = Authentication.getToken()
if (token) {
options.headers = options.headers || {}
options.headers['Authorization'] = 'Bearer ' + token
}
return m.request(options)
.catch(function (error) {
if (error.code === 403) {
Authentication.clearToken()
m.route.set('/login', { redirect: m.route.get() })
}
return Promise.reject(error)
})
}