Skip to content

Commit

Permalink
force auth in hdr
Browse files Browse the repository at this point in the history
  • Loading branch information
birm committed Mar 18, 2019
1 parent 7a44f08 commit d495da2
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 2 deletions.
72 changes: 72 additions & 0 deletions core/Store.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ try {
} catch (e) {
var b;
}

function getCookie(key) {
var cookiestring = RegExp("" + key + "[^;]+").exec(document.cookie);
return decodeURIComponent(!!cookiestring ? cookiestring.toString().replace(/^[^=]+./, "") : "");
}
/**
* converts an object into a string of url components
* @param {object} obj - keys and values
Expand Down Expand Up @@ -37,6 +42,7 @@ class Store {
this.base = base || "./data/";
this.validation = validation || {};
this.config = config;
this.auth = "Bearer " + getCookie('token');
}
/**
* errorHandler: handle the error response, and clean
Expand Down Expand Up @@ -113,6 +119,9 @@ class Store {
}
let bySlide = fetch(url + "?" + objToParamStr(query), {
credentials: "include",
headers: {
'Authorization': this.auth
},
mode: "cors"
}).then(this.errorHandler).then(x=>this.filterBroken(x, "mark"))
if (!slide) {
Expand All @@ -125,6 +134,9 @@ class Store {
query.slide = x[0]['_id']['$oid']
return fetch(url + "?" + objToParamStr(query), {
credentials: "include",
headers: {
'Authorization': this.auth
},
mode: "cors"
}).then(this.errorHandler).then(x=>this.filterBroken(x, "mark"))
}
Expand Down Expand Up @@ -167,6 +179,9 @@ class Store {

return fetch(url + "?" + objToParamStr(query), {
credentials: "include",
headers: {
'Authorization': this.auth
},
mode: "cors"
}).then(this.errorHandler).then(x=>this.filterBroken(x, "mark"))
}
Expand Down Expand Up @@ -212,6 +227,9 @@ class Store {

let bySlide = fetch(url + "?" + objToParamStr(query), {
credentials: "include",
headers: {
'Authorization': this.auth
},
mode: "cors"
}).then(this.errorHandler).then(x=>this.filterBroken(x, "mark"))
if (!slide) {
Expand All @@ -224,6 +242,9 @@ class Store {
query.slide = x[0]['_id']['$oid']
return fetch(url + "?" + objToParamStr(query), {
credentials: "include",
headers: {
'Authorization': this.auth
},
mode: "cors"
}).then(this.errorHandler).then(x=>this.filterBroken(x, "mark"))
}
Expand All @@ -249,6 +270,9 @@ class Store {

return fetch(url + "?" + objToParamStr(query), {
credentials: "include",
headers: {
'Authorization': this.auth
},
mode: "cors"
}).then(this.errorHandler).then(x=>this.filterBroken(x, "mark"))
}
Expand All @@ -266,6 +290,9 @@ class Store {
return fetch(url, {
method: "POST",
credentials: "include",
headers: {
'Authorization': this.auth
},
mode: "cors",
headers: {
"Content-Type": "application/json; charset=utf-8",
Expand All @@ -290,6 +317,9 @@ class Store {
return fetch(url + "?" + objToParamStr(query), {
method: "DELETE",
credentials: "include",
headers: {
'Authorization': this.auth
},
mode: "cors"
}).then(this.errorHandler)
}
Expand All @@ -312,6 +342,9 @@ class Store {
}
let bySlide = fetch(url + "?" + objToParamStr(query), {
credentials: "include",
headers: {
'Authorization': this.auth
},
mode: "cors"
}).then(this.errorHandler)

Expand All @@ -325,6 +358,9 @@ class Store {
query.slide = x[0]['_id']['$oid']
return fetch(url + "?" + objToParamStr(query), {
credentials: "include",
headers: {
'Authorization': this.auth
},
mode: "cors"
}).then(this.errorHandler)
}
Expand All @@ -347,6 +383,9 @@ class Store {
}
return fetch(url + "?" + objToParamStr(query), {
credentials: "include",
headers: {
'Authorization': this.auth
},
mode: "cors"
}).then(this.errorHandler).then(x=>this.filterBroken(x, "heatmap"))
}
Expand All @@ -363,6 +402,9 @@ class Store {
}
return fetch(url + "?" + objToParamStr(query), {
credentials: "include",
headers: {
'Authorization': this.auth
},
mode: "cors"
}).then(this.errorHandler).then(x=>this.filterBroken(x, "heatmap"))
}
Expand All @@ -380,6 +422,9 @@ class Store {

return fetch(url + "?" + objToParamStr(query), {
credentials: "include",
headers: {
'Authorization': this.auth
},
mode: "cors"
}).then(this.errorHandler).then(x=>this.filterBroken(x, "heatmap"))
}
Expand All @@ -399,6 +444,7 @@ class Store {
credentials: "include",
mode: "cors",
headers: {
'Authorization': this.auth,
"Content-Type": "application/json; charset=utf-8",
// "Content-Type": "application/x-www-form-urlencoded",
},
Expand All @@ -421,6 +467,9 @@ class Store {
return fetch(url + "?" + objToParamStr(query), {
method: "DELETE",
credentials: "include",
headers: {
'Authorization': this.auth
},
mode: "cors"
}).then(this.errorHandler)
}
Expand All @@ -444,6 +493,9 @@ class Store {

return fetch(url + "?" + objToParamStr(query), {
credentials: "include",
headers: {
'Authorization': this.auth
},
mode: "cors"
}).then(this.errorHandler)
}
Expand All @@ -462,6 +514,9 @@ class Store {

return fetch(url + "?" + objToParamStr(query), {
credentials: "include",
headers: {
'Authorization': this.auth
},
mode: "cors"
}).then(this.errorHandler)
}
Expand Down Expand Up @@ -491,6 +546,9 @@ class Store {

return fetch(url + "?" + objToParamStr(query), {
credentials: "include",
headers: {
'Authorization': this.auth
},
mode: "cors"
}).then(this.errorHandler)
}
Expand All @@ -509,6 +567,9 @@ class Store {

return fetch(url + "?" + objToParamStr(query), {
credentials: "include",
headers: {
'Authorization': this.auth
},
mode: "cors"
}).then(this.errorHandler).then(x=>this.filterBroken(x, "slide"))
}
Expand All @@ -532,6 +593,9 @@ class Store {

return fetch(url + "?" + objToParamStr(query), {
credentials: "include",
headers: {
'Authorization': this.auth
},
mode: "cors"
}).then(this.errorHandler).then(x=>this.filterBroken(x, "template"))
}
Expand All @@ -550,6 +614,9 @@ class Store {

return fetch(url + "?" + objToParamStr(query), {
credentials: "include",
headers: {
'Authorization': this.auth
},
mode: "cors"
}).then(this.errorHandler).then(x=>this.filterBroken(x, "template"))
}
Expand All @@ -570,6 +637,7 @@ class Store {
body: JSON.stringify(data),
credentials: "include",
headers: {
'Authorization': this.auth,
"Content-Type": "application/json; charset=utf-8"
}
}).then(this.errorHandler)
Expand All @@ -591,6 +659,7 @@ class Store {
body: JSON.stringify(data),
credentials: "include",
headers: {
'Authorization': this.auth,
"Content-Type": "application/json; charset=utf-8"
}
}).then(this.errorHandler)
Expand All @@ -607,6 +676,9 @@ class Store {

return fetch(url + "?" + objToParamStr(query), {
credentials: "include",
headers: {
'Authorization': this.auth
},
mode: "cors"
}).then(this.errorHandler)
}
Expand Down
2 changes: 1 addition & 1 deletion dist/pathdb_package.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d495da2

Please sign in to comment.