Skip to content

Commit 0b4576e

Browse files
committed
fix(pencil): Handle auth correctly
1 parent 067da87 commit 0b4576e

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/gatsby-node.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,26 @@ exports.sourceNodes = async (
2020
const {
2121
baseUrl,
2222
apiBase = "jsonapi",
23-
basicAuth,
24-
headers,
23+
basicAuth = {},
24+
headers = {},
2525
menus,
2626
} = pluginOptions
2727
const { createNode, createParentChildLink } = actions
2828

2929
reporter.info(`Starting to fetch menu link items from Drupal`)
3030
reporter.info("Menus to fetch are " + menus.join(", "))
3131

32+
if (basicAuth.username) {
33+
headers.Authorization = `Basic ${Buffer.from(
34+
`${basicAuth.username}:${basicAuth.password}`,
35+
"utf-8"
36+
).toString("base64")}`
37+
}
38+
3239
// Data can come from anywhere, but for now create it manually
3340
const menuResponses = await Promise.all(
3441
menus.map(async (menu) => {
3542
return await fetch(`${baseUrl}/${apiBase}/menu_items/${menu}`, {
36-
auth: basicAuth,
3743
headers,
3844
}).then(function (response) {
3945
if (response.status >= 400) {

0 commit comments

Comments
 (0)