From 9fefd728a27b2c2a99c7ed41d89011fc8f6c2710 Mon Sep 17 00:00:00 2001 From: Lukasz Ostrowski Date: Wed, 14 Jun 2023 15:46:51 +0200 Subject: [PATCH] fixed duplicated ProtectedHandlerContext (#255) --- .changeset/fifty-carrots-crash.md | 5 +++++ src/handlers/next/create-protected-handler.ts | 2 +- src/handlers/next/index.ts | 1 + src/handlers/next/process-protected-handler.ts | 10 ++-------- src/handlers/next/protected-handler-context.ts | 8 ++++++++ .../next/saleor-webhooks/process-saleor-webhook.ts | 5 ----- 6 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 .changeset/fifty-carrots-crash.md create mode 100644 src/handlers/next/protected-handler-context.ts diff --git a/.changeset/fifty-carrots-crash.md b/.changeset/fifty-carrots-crash.md new file mode 100644 index 0000000..3531cab --- /dev/null +++ b/.changeset/fifty-carrots-crash.md @@ -0,0 +1,5 @@ +--- +"@saleor/app-sdk": patch +--- + +Fixed invalid ProtectedHandlerContext that didnt include new user field diff --git a/src/handlers/next/create-protected-handler.ts b/src/handlers/next/create-protected-handler.ts index ec74b17..4402767 100644 --- a/src/handlers/next/create-protected-handler.ts +++ b/src/handlers/next/create-protected-handler.ts @@ -8,7 +8,7 @@ import { ProtectedHandlerError, SaleorProtectedHandlerError, } from "./process-protected-handler"; -import { ProtectedHandlerContext } from "./saleor-webhooks/process-saleor-webhook"; +import { ProtectedHandlerContext } from "./protected-handler-context"; const debug = createDebug("ProtectedHandler"); diff --git a/src/handlers/next/index.ts b/src/handlers/next/index.ts index 4df78d6..23ddd04 100644 --- a/src/handlers/next/index.ts +++ b/src/handlers/next/index.ts @@ -2,6 +2,7 @@ export * from "./create-app-register-handler"; export * from "./create-manifest-handler"; export * from "./create-protected-handler"; export * from "./process-protected-handler"; +export * from "./protected-handler-context"; export * from "./saleor-webhooks/saleor-async-webhook"; export * from "./saleor-webhooks/saleor-sync-webhook"; export { NextWebhookApiHandler } from "./saleor-webhooks/saleor-webhook"; diff --git a/src/handlers/next/process-protected-handler.ts b/src/handlers/next/process-protected-handler.ts index 22909b1..7322c70 100644 --- a/src/handlers/next/process-protected-handler.ts +++ b/src/handlers/next/process-protected-handler.ts @@ -1,12 +1,12 @@ import { NextApiRequest } from "next"; import { APL } from "../../APL"; -import { AuthData } from "../../APL/apl"; import { createDebug } from "../../debug"; import { getBaseUrl, getSaleorHeaders } from "../../headers"; import { Permission } from "../../types"; -import { extractUserFromJwt, TokenUserPayload } from "../../util/extract-user-from-jwt"; +import { extractUserFromJwt } from "../../util/extract-user-from-jwt"; import { verifyJWT } from "../../verify-jwt"; +import { ProtectedHandlerContext } from "./protected-handler-context"; const debug = createDebug("processProtectedHandler"); @@ -32,12 +32,6 @@ export class ProtectedHandlerError extends Error { } } -export type ProtectedHandlerContext = { - baseUrl: string; - authData: AuthData; - user: TokenUserPayload; -}; - interface ProcessSaleorProtectedHandlerArgs { req: Pick; apl: APL; diff --git a/src/handlers/next/protected-handler-context.ts b/src/handlers/next/protected-handler-context.ts new file mode 100644 index 0000000..71bb42d --- /dev/null +++ b/src/handlers/next/protected-handler-context.ts @@ -0,0 +1,8 @@ +import { AuthData } from "../../APL"; +import { TokenUserPayload } from "../../util/extract-user-from-jwt"; + +export type ProtectedHandlerContext = { + baseUrl: string; + authData: AuthData; + user: TokenUserPayload; +}; diff --git a/src/handlers/next/saleor-webhooks/process-saleor-webhook.ts b/src/handlers/next/saleor-webhooks/process-saleor-webhook.ts index 91a542f..1cc27f1 100644 --- a/src/handlers/next/saleor-webhooks/process-saleor-webhook.ts +++ b/src/handlers/next/saleor-webhooks/process-saleor-webhook.ts @@ -45,11 +45,6 @@ export type WebhookContext = { authData: AuthData; }; -export type ProtectedHandlerContext = { - baseUrl: string; - authData: AuthData; -}; - interface ProcessSaleorWebhookArgs { req: NextApiRequest; apl: APL;