Skip to content

Commit

Permalink
fix(gatsby-source-wordpress): allow using engines when using wordpres…
Browse files Browse the repository at this point in the history
…s auth (#38103)

Co-authored-by: Lennart <lekoarts@gmail.com>
  • Loading branch information
pieh and LekoArts authored May 25, 2023
1 parent ccbbda5 commit 7adb331
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
6 changes: 6 additions & 0 deletions packages/gatsby-source-wordpress/src/gatsby-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ exports[pluginInitApiName] = runApiSteps(
steps.setErrorMap,
steps.tempPreventMultipleInstances,
steps.setRequestHeaders,
steps.hideAuthPluginOptions,
],
pluginInitApiName
)

exports.onPreBootstrap = runApiSteps(
[steps.restoreAuthPluginOptions],
`onPreBootstrap`
)

exports.pluginOptionsSchema = steps.pluginOptionsSchema

exports.createSchemaCustomization = runApiSteps(
Expand Down
28 changes: 28 additions & 0 deletions packages/gatsby-source-wordpress/src/steps/auth-handling.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { GatsbyNodeApiHelpers } from "~/utils/gatsby-types"
import type { Step } from "./../utils/run-steps"
import type { IPluginOptions } from "~/models/gatsby-api"

let storedAuthSettings: IPluginOptions["auth"] | undefined

export const hideAuthPluginOptions: Step = async (
_helpers: GatsbyNodeApiHelpers,
pluginOptions: IPluginOptions
): Promise<void> => {
// store auth settings so we can restore them later
storedAuthSettings = pluginOptions.auth

// remove auth from pluginOptions before we write out browser plugin options module,
// so we don't leak into the browser
delete pluginOptions.auth
}

export const restoreAuthPluginOptions: Step = async (
_helpers: GatsbyNodeApiHelpers,
pluginOptions: IPluginOptions
): Promise<void> => {
if (storedAuthSettings) {
// if we stored auth settings, restore them now after we've written out browser plugin options module
// so engines can use them
pluginOptions.auth = storedAuthSettings
}
}
5 changes: 5 additions & 0 deletions packages/gatsby-source-wordpress/src/steps/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ export { logPostBuildWarnings } from "~/steps/log-post-build-warnings"
export { imageRoutes } from "~/steps/image-routes"

export { setRequestHeaders } from "./set-request-headers"

export {
hideAuthPluginOptions,
restoreAuthPluginOptions,
} from "./auth-handling"
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,5 @@ export const processAndValidatePluginOptions = (
}
})

// remove auth from pluginOptions so we don't leak into the browser
delete pluginOptions.auth

return userPluginOptions
}

0 comments on commit 7adb331

Please sign in to comment.