gitroomhq/postiz-app · error · HttpException

Failed to generate auth URL

Error message

Failed to generate auth URL

What it means

getIntegrationUrl wraps the auth URL generation in try/catch; any thrown error from the provider's generateAuthUrl (or the Redis writes before it) becomes a 500 'Failed to generate auth URL'. It's a catch-all masking the underlying provider/Redis failure.

Source

Thrown at apps/backend/src/public-api/routes/v1/public.integrations.controller.ts:380

        },
        400
      );
    }

    try {
      const { codeVerifier, state, url } =
        await integrationProvider.generateAuthUrl();

      if (refresh) {
        await ioRedis.set(`refresh:${state}`, refresh, 'EX', 3600);
      }

      await ioRedis.set(`organization:${state}`, org.id, 'EX', 3600);
      await ioRedis.set(`login:${state}`, codeVerifier, 'EX', 3600);

      return { url };
    } catch (err) {
      throw new HttpException({ msg: 'Failed to generate auth URL' }, 500);
    }
  }

  @Get('/users')
  @UseGuards(SuperAdminGuard)
  async listUsers(
    @GetOrgFromRequest() org: Organization,
    @Query('name') name: string
  ) {
    Sentry.metrics.count('public_api-request', 1);
    return this._usersService.getImpersonateUser(name);
  }

  @Get('/notifications')
  async getNotifications(
    @GetOrgFromRequest() org: Organization,
    @Query() query: GetNotificationsDto
  ) {

View on GitHub (pinned to 0f1647f749)

Solutions

  1. Check backend logs for the original swallowed error — the catch hides the real cause (add temporary logging if absent)
  2. Verify the env vars/credentials for the specific provider are set and non-empty
  3. Confirm Redis connectivity (REDIS_URL/host) — the state keys must be writable
  4. Verify the provider's OAuth app settings (redirect URI, client id) match the deployment

Example fix

// env: ensure provider credentials are set before requesting the auth URL
# before
# TWITTER_CLIENT_ID=
# TWITTER_CLIENT_SECRET=

# after
TWITTER_CLIENT_ID=xxxx
TWITTER_CLIENT_SECRET=yyyy
Defensive patterns

Strategy: retry

Validate before calling

// Fail fast on missing provider credentials and Redis before requesting the URL
assertEnv(`${integration.toUpperCase()}_CLIENT_ID`);
assertEnv(`${integration.toUpperCase()}_CLIENT_SECRET`);
await redis.ping();

Type guard

null

Try / catch

try {
  const { url } = await api.getIntegrationUrl(integrationId);
} catch (e) {
  if (e?.response?.status === 500 && e?.response?.data?.msg === 'Failed to generate auth URL') {
    await waitFor(1000); // transient Redis/provider hiccup — retry once
    return api.getIntegrationUrl(integrationId);
  }
  throw e;
}

Prevention

When it happens

Trigger: GET on the integration URL route when the provider's OAuth config is missing (client id/secret env vars unset for that provider), the OAuth client config is malformed, or Redis (ioRedis) is unreachable when persisting state/codeVerifier keys.

Common situations: Missing PROVIDER_CLIENT_ID/SECRET env vars for the requested integration; Redis connection down or misconfigured (wrong host/URL in a containerized setup); provider OAuth config renamed between versions; expired/rotated credentials causing provider SDK errors.

Related errors


AI-assisted analysis of gitroomhq/postiz-app@0f1647f749 (2026-08-27). Data as JSON: /api/errors/168431d028084282. Report an issue: GitHub.