* Fix Facebook and Instagram-via-Facebook Page connect pagination. Follow Graph API paging.next on /me/accounts so authorized non-first Pages are found and multi-Page accounts get the picker instead of silently connecting the first result. Co-authored-by: Cursor <cursoragent@cursor.com> * Paginate Meta accounts until paging.next is exhausted. Drop the artificial 50-page cap and stop only when there is no next URL, or the same request URL repeats (broken pagination loop). Co-authored-by: Cursor <cursoragent@cursor.com> * Redact tokens in Graph pagination logs and harden test coverage. Cover happy-path and failure cases for Meta /me/accounts pagination, including mid-loop failures, invalid paging.next, and Instagram pages without a linked IG account. Co-authored-by: Cursor <cursoragent@cursor.com> * Fail closed on incomplete Meta accounts pagination. If a later /me/accounts page fails after earlier pages succeeded, throw instead of returning a truncated list that could auto-connect the wrong Page. Also revert the IG detail timeout that could wipe the whole connect list. Co-authored-by: Cursor <cursoragent@cursor.com> * Simplify Graph pagination helpers and page fetchers. Bake the first request query into the URL, drop requestKey, and let IncompleteGraphPaginationException bubble from the controllers without catch/rethrow noise. Co-authored-by: Cursor <cursoragent@cursor.com> * Move incomplete pagination exception under Social\Meta. Colocate it with GraphPaginator so the Meta scope is clear from the namespace instead of a generic Social exception name. Co-authored-by: Cursor <cursoragent@cursor.com> * Rename pagination exception to IncompleteMetaGraphPaginationException. Keep it under Exceptions/Social with Meta in the class name instead of moving it into Services. Co-authored-by: Cursor <cursoragent@cursor.com> * Make GraphPaginator results explicit before mapping pages. Assign the paginated accounts to a variable first so the Facebook and Instagram-via-Facebook fetchers read more clearly. Co-authored-by: Cursor <cursoragent@cursor.com> * Build Meta Graph pagination URLs with Laravel Uri. Replace manual http_build_query concatenation with Uri::of()->withQuery(). Co-authored-by: Cursor <cursoragent@cursor.com> * Use Laravel HTTP and Uri helpers in Meta Graph pagination. Prefer response collect/json key access, filled(), and Uri path parsing over manual array and parse_url handling. Co-authored-by: Cursor <cursoragent@cursor.com> * Simplify graphVersion using Uri path and str(). Drop basename and native string casts; Uri::path() already yields the Graph API version segment. Co-authored-by: Cursor <cursoragent@cursor.com> * Drop unnecessary str() around graph API config. Uri: :of() already accepts the string returned by config(). Co-authored-by: Cursor <cursoragent@cursor.com> * Simplify GraphPaginator with Laravel helpers. Consolidate failure handling via abort(), and use collect, when, throw_if, and Uri::value() for a shorter pagination loop. Co-authored-by: Cursor <cursoragent@cursor.com> * Refactor social OAuth page/channel selection handling. Update selectPage and selectChannel methods in Facebook, Instagram, and YouTube controllers to return popup callbacks instead of redirecting on session expiration or workspace not found. Enhance HandleInertiaRequests middleware to prevent deferring onboarding progress on social OAuth popup routes. Add tests to verify behavior for expired sessions and onboarding progress. * Unify Instagram connect behind one card with a method picker. Hide the Instagram-via-Facebook grid card and offer Instagram Login vs Facebook Pages from a single network entry, matching LinkedIn. Co-authored-by: Cursor <cursoragent@cursor.com> * Move social popup onboarding assertions into connection tests. Cover the deferred-prop popup regression on Facebook, Instagram, and YouTube select routes instead of a synthetic onboarding share check. Co-authored-by: Cursor <cursoragent@cursor.com> * Stop suppressing onboarding defer on all social routes. Override onboardingProgress only in popupCallback so picker pages stay deferred and the close page does not re-hit select after session clear. Co-authored-by: Cursor <cursoragent@cursor.com> * Always open the Instagram method dialog on connect. Drop connectMethods and the single-method OAuth shortcut; the picker always offers both Login and Facebook Pages. Co-authored-by: Cursor <cursoragent@cursor.com> * Filter Instagram dialog options by enabled platforms. Keep always opening the method picker, but only list OAuth entry points that are turned on. Co-authored-by: Cursor <cursoragent@cursor.com> * Extract Instagram connect methods into a dedicated helper. Keep connectableOptions focused on shaping grid options while the enabled OAuth list lives in instagramConnectMethods(). Co-authored-by: Cursor <cursoragent@cursor.com> * Harden Meta Graph pagination and localize Instagram connect copy. Fail closed on Graph request errors and pathological paging, keep Instagram connect going when profile detail lookups time out, and translate the Instagram method dialog strings. Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
119 lines
4.7 KiB
PHP
119 lines
4.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Middleware\App;
|
|
|
|
use App\Actions\Onboarding\ResolveOnboardingStatus;
|
|
use App\Enums\PostPlatform\ContentType;
|
|
use App\Http\Resources\App\HandleInertiaRequests\AuthAccountResource;
|
|
use App\Http\Resources\App\HandleInertiaRequests\AuthPlanResource;
|
|
use App\Http\Resources\App\HandleInertiaRequests\AuthUserResource;
|
|
use App\Http\Resources\App\HandleInertiaRequests\AuthWorkspaceResource;
|
|
use App\Models\User;
|
|
use Illuminate\Http\Request;
|
|
use Inertia\DeferProp;
|
|
use Inertia\Inertia;
|
|
use Inertia\Middleware;
|
|
|
|
class HandleInertiaRequests extends Middleware
|
|
{
|
|
protected $rootView = 'app';
|
|
|
|
public function version(Request $request): ?string
|
|
{
|
|
return parent::version($request);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function share(Request $request): array
|
|
{
|
|
$user = $request->user();
|
|
|
|
$currentWorkspace = $user?->currentWorkspace?->load('media');
|
|
$account = $user?->account;
|
|
$isSelfHosted = (bool) config('trypost.self_hosted');
|
|
|
|
return [
|
|
...parent::share($request),
|
|
'name' => config('app.name'),
|
|
'auth' => [
|
|
'user' => $user ? AuthUserResource::make($user) : null,
|
|
'currentWorkspace' => $currentWorkspace ? AuthWorkspaceResource::make($currentWorkspace, $user) : null,
|
|
'workspaces' => $user
|
|
? $user->workspaces()->with('media')->get()->map(fn ($ws) => AuthWorkspaceResource::summary($ws))
|
|
: [],
|
|
'account' => $account ? AuthAccountResource::make($account) : null,
|
|
'plan' => $account && $account->plan ? AuthPlanResource::make($account, $account->plan) : null,
|
|
'hasActiveSubscription' => $account ? $account->hasActiveSubscription() : false,
|
|
'subscriptionPastDue' => $account ? $account->isPastDue() : false,
|
|
],
|
|
'usage' => $account && ! $isSelfHosted ? $account->usage() : null,
|
|
'features' => $account && ! $isSelfHosted ? $account->featureLimits() : null,
|
|
'onboardingProgress' => $this->onboardingProgress($request, $user),
|
|
'sidebarOpen' => ! $request->hasCookie('sidebar_state') || $request->cookie('sidebar_state') === 'true',
|
|
'flash' => $request->session()->get('flash', []),
|
|
'applicationUrl' => config('app.url'),
|
|
'env' => config('app.env'),
|
|
'locale' => app()->getLocale(),
|
|
'languages' => collect(config('languages.available'))->map(fn ($name, $code) => [
|
|
'code' => $code,
|
|
'name' => $name,
|
|
])->values()->all(),
|
|
'aiEnabled' => ! empty(config('services.gemini.api_key')) || ! empty(config('services.openai.api_key')),
|
|
'selfHosted' => $isSelfHosted,
|
|
'googleAuthEnabled' => config('trypost.google_auth_enabled'),
|
|
'githubAuthEnabled' => config('trypost.github_auth_enabled'),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, callable>
|
|
*/
|
|
public function shareOnce(Request $request): array
|
|
{
|
|
return [
|
|
...parent::shareOnce($request),
|
|
'contentTypeMediaRules' => fn (): array => ContentType::mediaRulesForFrontend(),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Defer step queries for mid-activation owners; everyone else gets false inline.
|
|
*
|
|
* Never defer on Passport consent *views*: Inertia deferred props re-request the
|
|
* same URL, Passport rotates `authToken` on every authorize hit, and approve then
|
|
* fails with InvalidAuthTokenException against the stale token still on the page.
|
|
*
|
|
* Social OAuth popup close pages set `onboardingProgress` to false in
|
|
* `SocialController::popupCallback()` so a deferred reload does not re-hit the
|
|
* select route after the connect session was cleared.
|
|
*/
|
|
private function onboardingProgress(Request $request, ?User $user): DeferProp|false
|
|
{
|
|
if ($this->isPassportConsentViewRequest($request)) {
|
|
return false;
|
|
}
|
|
|
|
$onboarding = app(ResolveOnboardingStatus::class);
|
|
|
|
return $user && $onboarding->canShowProgress($user)
|
|
? Inertia::defer(fn (): array|false => $onboarding->sidebarProgress($user))
|
|
: false;
|
|
}
|
|
|
|
/**
|
|
* Exact GET consent-view route names only — not approve/deny, and not wildcards
|
|
* like passport.authorizations.* (those would suppress defer on POST approve too,
|
|
* which is unnecessary and easy to misread as "all OAuth").
|
|
*/
|
|
private function isPassportConsentViewRequest(Request $request): bool
|
|
{
|
|
return $request->routeIs(
|
|
'passport.authorizations.authorize',
|
|
'passport.device.authorizations.authorize',
|
|
);
|
|
}
|
|
}
|