Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

fix: surface real WordPress connect errors and normalize domain

Gilad Resisi3c7a68639886
diff --git a/apps/frontend/src/components/launches/add.provider.component.tsx b/apps/frontend/src/components/launches/add.provider.component.tsx
index 96ad25d08..9ff651acb 100644
--- a/apps/frontend/src/components/launches/add.provider.component.tsx
+++ b/apps/frontend/src/components/launches/add.provider.component.tsx
@@ -165,6 +165,7 @@ export const CustomVariables: FC<{
defaultValue?: string;
validation: string;
type: 'text' | 'password';
+ hint?: string;
}>;
close?: () => void;
identifier: string;
@@ -236,11 +237,31 @@ export const CustomVariables: FC<{
>
{variables.map((variable) => (
<div key={variable.key}>
- <Input
- label={variable.label}
- name={variable.key}
- type={variable.type == 'text' ? 'text' : 'password'}
- />
+ {variable.hint ? (
+ <div className="flex flex-col gap-[6px]">
+ <div className="text-[14px] flex items-center gap-[6px]">
+ <span>{variable.label}</span>
+ <span
+ data-tooltip-id="tooltip"
+ data-tooltip-content={variable.hint}
+ className="w-[16px] h-[16px] rounded-full border border-textColor/60 text-textColor/60 flex items-center justify-center text-[11px] leading-none cursor-help select-none"
+ >
+ i
+ </span>
+ </div>
+ <Input
+ label=""
+ name={variable.key}
+ type={variable.type == 'text' ? 'text' : 'password'}
+ />
+ </div>
+ ) : (
+ <Input
+ label={variable.label}
+ name={variable.key}
+ type={variable.type == 'text' ? 'text' : 'password'}
+ />
+ )}
</div>
))}
<div>
@@ -372,6 +393,7 @@ export const AddProviderComponent: FC<{
label: string;
validation: string;
type: 'text' | 'password';
+ hint?: string;
}>;
}>;
article: Array<{
@@ -402,6 +424,7 @@ export const AddProviderComponent: FC<{
validation: string;
defaultValue?: string;
type: 'text' | 'password';
+ hint?: string;
}>
) =>
async () => {
diff --git a/libraries/nestjs-libraries/src/integrations/social/social.integrations.interface.ts b/libraries/nestjs-libraries/src/integrations/social/social.integrations.interface.ts
index f8b706d3d..1ad3cd7fa 100644
--- a/libraries/nestjs-libraries/src/integrations/social/social.integrations.interface.ts
+++ b/libraries/nestjs-libraries/src/integrations/social/social.integrations.interface.ts
@@ -161,6 +161,7 @@ export interface SocialProvider
defaultValue?: string;
validation: string;
type: 'text' | 'password';
+ hint?: string;
}[]
>;
name: string;
diff --git a/libraries/nestjs-libraries/src/integrations/social/wordpress.provider.ts b/libraries/nestjs-libraries/src/integrations/social/wordpress.provider.ts
index cda50772a..bbe4897d5 100644
--- a/libraries/nestjs-libraries/src/integrations/social/wordpress.provider.ts
+++ b/libraries/nestjs-libraries/src/integrations/social/wordpress.provider.ts
@@ -83,6 +83,7 @@ export class WordpressProvider
label: 'Password',
validation: `/.+/`,
type: 'password' as const,
+ hint: 'Application password, create in User->Profile',
},
];
}
@@ -97,45 +98,97 @@ export class WordpressProvider
username: string;
password: string;
};
+
+ // Normalize the domain - users often paste it with surrounding whitespace
+ // or a trailing slash, which would otherwise build `https://site.com//wp-json/...`.
+ const domain = body.domain.trim().replace(/\/+$/, '');
+
+ const auth = Buffer.from(`${body.username}:${body.password}`).toString(
+ 'base64'
+ );
+
+ // Direct fetch (not `this.fetch`) so we can branch on the HTTP status and
+ // return a specific message instead of throwing a generic error.
+ let response: Response;
try {
- const auth = Buffer.from(`${body.username}:${body.password}`).toString(
- 'base64'
- );
- const { id, name, avatar_urls, code } = await (
- await fetch(`${body.domain}/wp-json/wp/v2/users/me`, {
- headers: {
- Authorization: `Basic ${auth}`,
- },
+ response = await fetch(`${domain}/wp-json/wp/v2/users/me`, {
+ headers: {
+ Authorization: `Basic ${auth}`,
+ },
+ });
+ } catch (err) {
+ // DNS failure, connection refused, TLS error, site unreachable, etc.
+ console.log(err);
+ return 'Could not reach your WordPress site. Check the Domain URL and that the site is publicly accessible.';
+ }
+
+ // A security plugin (e.g. Wordfence), a WAF, or the server config commonly
+ // strips the Authorization header or locks down the REST API. We don't try
+ // to work around that - surface a distinct, actionable message instead.
+ if (!response.ok) {
+ // Log what WordPress actually returned (REST errors carry a `code` and
+ // `message`) so failures can be diagnosed without guessing.
+ const errorBody = await response.text().catch(() => '');
+ let wpCode = '';
+ let wpMessage = '';
+ try {
+ const parsed = JSON.parse(errorBody);
+ wpCode = parsed?.code || '';
+ wpMessage = parsed?.message || '';
+ } catch (err) {
+ // Non-JSON error body (e.g. an HTML page from a security plugin).
+ }
+ console.log(
+ `WordPress auth failed for ${domain} (HTTP ${response.status})`,
+ JSON.stringify({
+ code: wpCode,
+ message: wpMessage,
+ ...(wpCode ? {} : { body: errorBody.slice(0, 500) }),
})
- ).json();
+ );
- if (code) {
- throw "Invalid credentials";
+ if (response.status === 401 || response.status === 403) {
+ return 'WordPress rejected the login. A security plugin or server setting may be blocking the REST API or stripping the Authorization header, or the username / Application Password is incorrect.';
}
- const biggestImage = Object.entries(avatar_urls || {}).reduce(
- (all, current) => {
- if (all > Number(current[0])) {
- return all;
- }
- return Number(current[0]);
- },
- 0
- );
+ return `WordPress returned an unexpected error (HTTP ${response.status}). Make sure the REST API is enabled and Application Passwords are available.`;
+ }
- return {
- refreshToken: '',
- expiresIn: dayjs().add(100, 'years').unix() - dayjs().unix(),
- accessToken: params.code,
- id: body.domain + '_' + id,
- name,
- picture: avatar_urls?.[String(biggestImage)] || '',
- username: body.username,
- };
+ // Even on a 200, a security plugin / maintenance page can return HTML
+ // instead of JSON, which would otherwise throw on `.json()`.
+ let data: any;
+ try {
+ data = await response.json();
} catch (err) {
console.log(err);
+ return 'WordPress did not return a valid response. The REST API may be disabled or blocked by a security plugin.';
+ }
+
+ const { id, name, avatar_urls, code } = data || {};
+
+ if (code) {
return 'Invalid credentials';
}
+
+ const biggestImage = Object.entries(avatar_urls || {}).reduce(
+ (all, current) => {
+ if (all > Number(current[0])) {
+ return all;
+ }
+ return Number(current[0]);
+ },
+ 0
+ );
+
+ return {
+ refreshToken: '',
+ expiresIn: dayjs().add(100, 'years').unix() - dayjs().unix(),
+ accessToken: params.code,
+ id: body.domain + '_' + id,
+ name,
+ picture: avatar_urls?.[String(biggestImage)] || '',
+ username: body.username,
+ };
}
@Tool({