Browse Source

pass credentials with AJAX requests (#104)

This is necessary for identity-aware proxies to work.
dependabot/npm_and_yarn/web/prismjs-1.21.0
memory 8 years ago
committed by Max Schmitt
parent
commit
b92f3df301
  1. 3
      static/src/index.js
  2. 4
      static/src/util/util.js

3
static/src/index.js

@ -30,7 +30,7 @@ export default class BaseComponent extends Component {
} }
componentDidMount() { componentDidMount() {
fetch('/api/v1/info') fetch('/api/v1/info', {credentials: 'include'})
.then(d => d.json()) .then(d => d.json())
.then(info => this.setState({ info })) .then(info => this.setState({ info }))
.then(() => this.checkAuth()) .then(() => this.checkAuth())
@ -42,6 +42,7 @@ export default class BaseComponent extends Component {
if (token) { if (token) {
fetch('/api/v1/auth/check', { fetch('/api/v1/auth/check', {
method: 'POST', method: 'POST',
credentials: 'include',
body: JSON.stringify({ body: JSON.stringify({
Token: token Token: token
}), }),

4
static/src/util/util.js

@ -2,7 +2,7 @@ import toastr from 'toastr'
export default class UtilHelper { export default class UtilHelper {
static deleteEntry(url, cb) { static deleteEntry(url, cb) {
fetch(url) fetch(url, {credentials: "include"})
.then(res => res.ok ? res.json() : Promise.reject(res.json())) .then(res => res.ok ? res.json() : Promise.reject(res.json()))
.then(cb()) .then(cb())
.catch(e => this._reportError(e, "delete entry")) .catch(e => this._reportError(e, "delete entry"))
@ -10,6 +10,7 @@ export default class UtilHelper {
static _constructFetch(url, body, cbSucc, cbErr) { static _constructFetch(url, body, cbSucc, cbErr) {
fetch(url, { fetch(url, {
method: "POST", method: "POST",
credentials: "include",
body: JSON.stringify(body), body: JSON.stringify(body),
headers: { headers: {
'Authorization': window.localStorage.getItem('token'), 'Authorization': window.localStorage.getItem('token'),
@ -45,6 +46,7 @@ export default class UtilHelper {
} }
static getRecentURLs(cbSucc) { static getRecentURLs(cbSucc) {
fetch('/api/v1/protected/recent', { fetch('/api/v1/protected/recent', {
credentials: "include",
headers: { headers: {
'Authorization': window.localStorage.getItem('token'), 'Authorization': window.localStorage.getItem('token'),
'Content-Type': 'application/json' 'Content-Type': 'application/json'

Loading…
Cancel
Save