feat: Attach the Authorization header if a wpAuthToken is present in the context

This commit is contained in:
2026-03-26 15:32:13 -04:00
parent c9a9e03b60
commit 30c7b8b0b5
6 changed files with 124 additions and 26 deletions

View File

@@ -1,3 +1,4 @@
export default defineGraphQLContext(async (event) => {
return {};
const wpAuthToken = await getAuthToken(event);
return { wpAuthToken };
});

View 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}` },
});
}
},
});