Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Commit

Permalink
fix(xhr_wrapper): remove getLocalToken because we use cookies
Browse files Browse the repository at this point in the history
fix(xhr_wrapper): remove `getLocalToken` because we use cookies
  • Loading branch information
Metnew committed Nov 8, 2017
1 parent 8f587e0 commit 033c886
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions src/common/api/utils/xhr_wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @flow
*/

import {getLocalToken, resetLocalToken} from 'api/LocalStorageCookiesSvc'
import {resetLocalToken} from 'api/LocalStorageCookiesSvc'
import fetch from 'isomorphic-fetch'
import _ from 'lodash'

Expand Down Expand Up @@ -117,37 +117,26 @@ function decorateRequest ({method, url, data, options, cb}): Object {
// Default params for fetch = method + (Content-Type)
const defaults = {
method,
headers: {}
headers: {},
credentials: 'same-origin'
}
const token: string | null = getLocalToken()

const isRequestToExternalResource = /(http|https):\/\//.test(url)
const requestURL = isRequestToExternalResource
? url
: process.env.BASE_API + url

const requestAuthDecoration =
!isRequestToExternalResource && token
? {headers: {Authorization: `JWT ${token}`}}
: {}

const requestHeadersDataDecoration = getHeaderDataDecoration(data)

const request = cb(
_.merge(
{},
defaults,
options,
requestAuthDecoration,
requestHeadersDataDecoration
)
)

// if (!isRequestToExternalResource) {
// console.log(`Request ${url} was sent to our domain`, request)
// } else {
// console.log(`Request ${url} was sent to external domain`, request)
// }

return {
request,
requestURL
Expand All @@ -170,8 +159,3 @@ export const post = requestWrapper('POST')
export const put = requestWrapper('PUT')
export const patch = requestWrapper('PATCH')
export const del = requestWrapper('DELETE')

// USAGE:
// get('https://www.google.com', options)
//
// post('https://www.google.com', data, options)

0 comments on commit 033c886

Please sign in to comment.