Skip to content

Commit

Permalink
Added WPCOM authentication header to first request (gatsbyjs#8110)
Browse files Browse the repository at this point in the history
* Added WPCOM authentication header to first request

When hosted on a WPCOM private blog, the first request fetching the valid routes from the API must be authenticated. I fixed this by attaching the Authorization header along with the Bearer auth token we got.

Also, having an auth set when doing this request did not work. Removing the options.auth when uneccessary (i.e. no credentials given) worked.

* fix linting
  • Loading branch information
lazharichir authored and pieh committed Sep 13, 2018
1 parent 6d34607 commit 5d6b9b8
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/gatsby-source-wordpress/src/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,19 @@ Mama Route URL: ${url}
method: `get`,
url: url,
}
if (_auth) {
if (_auth && (_auth.htaccess_user || _auth.htaccess_pass)) {
options.auth = {
username: _auth.htaccess_user,
password: _auth.htaccess_pass,
}
}

if (_hostingWPCOM && _accessToken) {
options.headers = {
Authorization: `Bearer ${_accessToken}`,
}
}

allRoutes = await axios(options)
} catch (e) {
httpExceptionHandler(e)
Expand Down

0 comments on commit 5d6b9b8

Please sign in to comment.