feat: Attach the Authorization header if a wpAuthToken is present in the context
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
export default defineGraphQLContext(async (event) => {
|
||||
return {};
|
||||
const wpAuthToken = await getAuthToken(event);
|
||||
return { wpAuthToken };
|
||||
});
|
||||
|
||||
12
wp-content/themes/headless/server/graphql/wp-hooks.ts
Normal file
12
wp-content/themes/headless/server/graphql/wp-hooks.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { defu } from "defu";
|
||||
|
||||
export default defineRemoteExecutorHooks({
|
||||
onRequest(request, context) {
|
||||
// Attach the Authorization header if a wpAuthToken is present in the context
|
||||
if (context?.wpAuthToken) {
|
||||
request.extensions = defu(request.extensions, {
|
||||
headers: { Authorization: `Bearer ${context.wpAuthToken}` },
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user