diff --git a/apps/backend/src/route-handlers/smart-request.tsx b/apps/backend/src/route-handlers/smart-request.tsx index 3fe6644f9..6e017dd6e 100644 --- a/apps/backend/src/route-handlers/smart-request.tsx +++ b/apps/backend/src/route-handlers/smart-request.tsx @@ -158,21 +158,21 @@ async function parseAuth(req: NextRequest): Promise { case "client": { if (!publishableClientKey) throw new KnownErrors.ClientAuthenticationRequired(); const isValid = await checkApiKeySet(projectId, { publishableClientKey }); - if (!isValid) throw new KnownErrors.InvalidPublishableClientKey(); + if (!isValid) throw new KnownErrors.InvalidPublishableClientKey(projectId); projectAccessType = "key"; break; } case "server": { if (!secretServerKey) throw new KnownErrors.ServerAuthenticationRequired(); const isValid = await checkApiKeySet(projectId, { secretServerKey }); - if (!isValid) throw new KnownErrors.InvalidSecretServerKey(); + if (!isValid) throw new KnownErrors.InvalidSecretServerKey(projectId); projectAccessType = "key"; break; } case "admin": { if (!superSecretAdminKey) throw new KnownErrors.AdminAuthenticationRequired(); const isValid = await checkApiKeySet(projectId, { superSecretAdminKey }); - if (!isValid) throw new KnownErrors.InvalidSuperSecretAdminKey(); + if (!isValid) throw new KnownErrors.InvalidSuperSecretAdminKey(projectId); projectAccessType = "key"; break; } diff --git a/apps/dashboard/src/route-handlers/smart-request.tsx b/apps/dashboard/src/route-handlers/smart-request.tsx index b188ac82e..1f9c6bcd4 100644 --- a/apps/dashboard/src/route-handlers/smart-request.tsx +++ b/apps/dashboard/src/route-handlers/smart-request.tsx @@ -158,21 +158,21 @@ async function parseAuth(req: NextRequest): Promise { case "client": { if (!publishableClientKey) throw new KnownErrors.ClientAuthenticationRequired(); const isValid = await checkApiKeySet(projectId, { publishableClientKey }); - if (!isValid) throw new KnownErrors.InvalidPublishableClientKey(); + if (!isValid) throw new KnownErrors.InvalidPublishableClientKey(projectId); projectAccessType = "key"; break; } case "server": { if (!secretServerKey) throw new KnownErrors.ServerAuthenticationRequired(); const isValid = await checkApiKeySet(projectId, { secretServerKey }); - if (!isValid) throw new KnownErrors.InvalidSecretServerKey(); + if (!isValid) throw new KnownErrors.InvalidSecretServerKey(projectId); projectAccessType = "key"; break; } case "admin": { if (!superSecretAdminKey) throw new KnownErrors.AdminAuthenticationRequired(); const isValid = await checkApiKeySet(projectId, { superSecretAdminKey }); - if (!isValid) throw new KnownErrors.InvalidSuperSecretAdminKey(); + if (!isValid) throw new KnownErrors.InvalidSuperSecretAdminKey(projectId); projectAccessType = "key"; break; } diff --git a/packages/stack-shared/src/known-errors.tsx b/packages/stack-shared/src/known-errors.tsx index 99d4ae58f..dba8f38d2 100644 --- a/packages/stack-shared/src/known-errors.tsx +++ b/packages/stack-shared/src/known-errors.tsx @@ -240,31 +240,40 @@ const RequestTypeWithoutProjectId = createKnownErrorConstructor( const InvalidPublishableClientKey = createKnownErrorConstructor( InvalidProjectAuthentication, "INVALID_PUBLISHABLE_CLIENT_KEY", - () => [ + (projectId: string) => [ 401, - "The publishable key is not valid for the given project. Does the project and/or the key exist?", + `The publishable key is not valid for the project ${JSON.stringify(projectId)}. Does the project and/or the key exist?`, + { + projectId, + }, ] as const, - () => [] as const, + (json: any) => [json.projectId] as const, ); const InvalidSecretServerKey = createKnownErrorConstructor( InvalidProjectAuthentication, "INVALID_SECRET_SERVER_KEY", - () => [ + (projectId: string) => [ 401, - "The secret server key is not valid for the given project. Does the project and/or the key exist?", + `The secret server key is not valid for the project ${JSON.stringify(projectId)}. Does the project and/or the key exist?`, + { + projectId, + }, ] as const, - () => [] as const, + (json: any) => [json.projectId] as const, ); const InvalidSuperSecretAdminKey = createKnownErrorConstructor( InvalidProjectAuthentication, "INVALID_SUPER_SECRET_ADMIN_KEY", - () => [ + (projectId: string) => [ 401, - "The super secret admin key is not valid for the given project. Does the project and/or the key exist?", + `The super secret admin key is not valid for the project ${JSON.stringify(projectId)}. Does the project and/or the key exist?`, + { + projectId, + }, ] as const, - () => [] as const, + (json: any) => [json.projectId] as const, ); const InvalidAdminAccessToken = createKnownErrorConstructor(