Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.
PHP ai-agentsblueskyfacebookinstagramlaravellinkedinmastodonmcpmcp-serveropen-sourcerest-apiself-hostedsocial-mediasocial-media-managementsocial-media-schedulerthreadstiktokvuejsxyoutube
fix: self-host billing bypass, Facebook API metrics migration, X token refresh, and duplicate social accounts
Paulo Castellanoa8bb44f0e5bb
diff --git a/app/Http/Controllers/App/BillingController.php b/app/Http/Controllers/App/BillingController.phpindex ae76d51c5..91d8707a9 100644--- a/app/Http/Controllers/App/BillingController.php+++ b/app/Http/Controllers/App/BillingController.php@@ -16,6 +16,10 @@ class BillingController extends Controller{public function subscribe(Request $request): Response|RedirectResponse{+ if (config('trypost.self_hosted')) {+ return redirect()->route('app.calendar');+ }+$account = $request->user()->account;if ($account && $account->hasActiveSubscription()) {@@ -28,8 +32,12 @@ class BillingController extends Controller]);}- public function checkout(Request $request, Plan $plan): SymfonyResponse+ public function checkout(Request $request, Plan $plan): SymfonyResponse|RedirectResponse{+ if (config('trypost.self_hosted')) {+ return redirect()->route('app.calendar');+ }+$user = $request->user();$account = $user->account;@@ -66,8 +74,12 @@ class BillingController extends Controllerreturn Inertia::location($checkoutSession->url);}- public function processing(Request $request): Response+ public function processing(Request $request): Response|RedirectResponse{+ if (config('trypost.self_hosted')) {+ return redirect()->route('app.calendar');+ }+$account = $request->user()->account;return Inertia::render('billing/Processing', [@@ -75,8 +87,12 @@ class BillingController extends Controller]);}- public function index(Request $request): Response+ public function index(Request $request): Response|RedirectResponse{+ if (config('trypost.self_hosted')) {+ return redirect()->route('app.calendar');+ }+$account = $request->user()->account;abort_unless($request->user()->isAccountOwner(), SymfonyResponse::HTTP_FORBIDDEN);@@ -111,6 +127,10 @@ class BillingController extends Controllerpublic function swap(Request $request, Plan $plan): RedirectResponse{+ if (config('trypost.self_hosted')) {+ return redirect()->route('app.calendar');+ }+$account = $request->user()->account;abort_unless($request->user()->isAccountOwner(), SymfonyResponse::HTTP_FORBIDDEN);@@ -136,6 +156,10 @@ class BillingController extends Controllerpublic function portal(Request $request): RedirectResponse{+ if (config('trypost.self_hosted')) {+ return redirect()->route('app.calendar');+ }+$account = $request->user()->account;abort_unless($request->user()->isAccountOwner(), SymfonyResponse::HTTP_FORBIDDEN);diff --git a/app/Http/Controllers/App/Settings/AccountController.php b/app/Http/Controllers/App/Settings/AccountController.phpindex 39f60ec08..3f433e1b9 100644--- a/app/Http/Controllers/App/Settings/AccountController.php+++ b/app/Http/Controllers/App/Settings/AccountController.php@@ -25,6 +25,7 @@ class AccountController extends Controller'name' => $account->name,'billing_email' => $account->billing_email,],+ 'selfHosted' => config('trypost.self_hosted'),]);}@@ -32,19 +33,24 @@ class AccountController extends Controller{abort_unless($request->user()->isAccountOwner(), SymfonyResponse::HTTP_FORBIDDEN);+ $isSelfHosted = config('trypost.self_hosted');+$validated = $request->validate(['name' => ['required', 'string', 'max:255'],- 'billing_email' => ['required', 'email', 'max:255'],+ 'billing_email' => [$isSelfHosted ? 'nullable' : 'required', 'email', 'max:255'],]);$account = $request->user()->account;- $account->update([- 'name' => data_get($validated, 'name'),- 'billing_email' => data_get($validated, 'billing_email'),- ]);+ $data = ['name' => data_get($validated, 'name')];++ if (! $isSelfHosted) {+ $data['billing_email'] = data_get($validated, 'billing_email');+ }++ $account->update($data);- if ($account->hasStripeId()) {+ if (! $isSelfHosted && $account->hasStripeId()) {$account->updateStripeCustomer(['name' => data_get($validated, 'name'),'email' => data_get($validated, 'billing_email'),diff --git a/app/Http/Controllers/App/Settings/UsageController.php b/app/Http/Controllers/App/Settings/UsageController.phpindex 6f30b4c06..e53a83420 100644--- a/app/Http/Controllers/App/Settings/UsageController.php+++ b/app/Http/Controllers/App/Settings/UsageController.php@@ -11,6 +11,7 @@ use App\Features\MemberLimit;use App\Features\SocialAccountLimit;use App\Features\WorkspaceLimit;use App\Http\Controllers\App\Controller;+use Illuminate\Http\RedirectResponse;use Illuminate\Http\Request;use Inertia\Inertia;use Inertia\Response;@@ -19,8 +20,12 @@ use Symfony\Component\HttpFoundation\Response as SymfonyResponse;class UsageController extends Controller{- public function index(Request $request): Response+ public function index(Request $request): Response|RedirectResponse{+ if (config('trypost.self_hosted')) {+ return redirect()->route('app.calendar');+ }+abort_unless($request->user()->isAccountOwner(), SymfonyResponse::HTTP_FORBIDDEN);$account = $request->user()->account;diff --git a/app/Http/Controllers/Auth/BlueskyController.php b/app/Http/Controllers/Auth/BlueskyController.phpindex f799f9935..b29ce169d 100644--- a/app/Http/Controllers/Auth/BlueskyController.php+++ b/app/Http/Controllers/Auth/BlueskyController.php@@ -89,23 +89,28 @@ class BlueskyController extends SocialController$avatarPath = data_get($profile, 'avatar') ? uploadFromUrl(data_get($profile, 'avatar')) : null;- // Create new account- $workspace->socialAccounts()->create([- 'platform' => $this->platform->value,- 'platform_user_id' => data_get($data, 'did'),- 'username' => data_get($data, 'handle'),- 'display_name' => data_get($profile, 'displayName', data_get($data, 'handle')),- 'avatar_url' => $avatarPath,- 'access_token' => data_get($data, 'accessJwt'),- 'refresh_token' => data_get($data, 'refreshJwt'),- 'token_expires_at' => now()->addHours(2),- 'status' => Status::Connected,- 'meta' => [- 'service' => $service,- 'identifier' => $request->identifier,- 'password' => encrypt($request->password),+ $workspace->socialAccounts()->updateOrCreate(+ [+ 'platform' => $this->platform->value,+ 'platform_user_id' => data_get($data, 'did'),],- ]);+ [+ 'username' => data_get($data, 'handle'),+ 'display_name' => data_get($profile, 'displayName', data_get($data, 'handle')),+ 'avatar_url' => $avatarPath,+ 'access_token' => data_get($data, 'accessJwt'),+ 'refresh_token' => data_get($data, 'refreshJwt'),+ 'token_expires_at' => now()->addHours(2),+ 'status' => Status::Connected,+ 'error_message' => null,+ 'disconnected_at' => null,+ 'meta' => [+ 'service' => $service,+ 'identifier' => $request->identifier,+ 'password' => encrypt($request->password),+ ],+ ],+ );return $this->popupCallback(true, 'Bluesky account connected!', $this->platform->value);} catch (\Exception $e) {diff --git a/app/Http/Controllers/Auth/FacebookController.php b/app/Http/Controllers/Auth/FacebookController.phpindex a2f55aae4..ff6aef0cb 100644--- a/app/Http/Controllers/Auth/FacebookController.php+++ b/app/Http/Controllers/Auth/FacebookController.php@@ -95,24 +95,29 @@ class FacebookController extends SocialController$page = $pages[0];$avatarPath = uploadFromUrl(data_get($page, 'picture'));- // Create new account- $workspace->socialAccounts()->create([- 'platform' => $this->platform->value,- 'platform_user_id' => data_get($page, 'id'),- 'username' => data_get($page, 'username', null),- 'display_name' => data_get($page, 'name'),- 'avatar_url' => $avatarPath,- 'access_token' => data_get($page, 'access_token'),- 'refresh_token' => null, // Page tokens don't expire if user token is long-lived- 'token_expires_at' => null,- 'scopes' => $this->scopes,- 'status' => Status::Connected,- 'meta' => [- 'page_id' => data_get($page, 'id'),- 'user_id' => $socialUser->getId(),- 'user_token' => $socialUser->token,+ $workspace->socialAccounts()->updateOrCreate(+ [+ 'platform' => $this->platform->value,+ 'platform_user_id' => data_get($page, 'id'),],- ]);+ [+ 'username' => data_get($page, 'username', null),+ 'display_name' => data_get($page, 'name'),+ 'avatar_url' => $avatarPath,+ 'access_token' => data_get($page, 'access_token'),+ 'refresh_token' => null,+ 'token_expires_at' => null,+ 'scopes' => $this->scopes,+ 'status' => Status::Connected,+ 'error_message' => null,+ 'disconnected_at' => null,+ 'meta' => [+ 'page_id' => data_get($page, 'id'),+ 'user_id' => $socialUser->getId(),+ 'user_token' => $socialUser->token,+ ],+ ],+ );return $this->popupCallback(true, 'Facebook Page connected!', $this->platform->value);}@@ -225,24 +230,29 @@ class FacebookController extends SocialController}}- // Create new account- $workspace->socialAccounts()->create([- 'platform' => $this->platform->value,- 'platform_user_id' => data_get($selectedPage, 'id'),- 'username' => data_get($selectedPage, 'username') ?? null,- 'display_name' => data_get($selectedPage, 'name'),- 'avatar_url' => $avatarPath,- 'access_token' => data_get($selectedPage, 'access_token'),- 'refresh_token' => null,- 'token_expires_at' => null,- 'scopes' => $this->scopes,- 'status' => Status::Connected,- 'meta' => [- 'page_id' => data_get($selectedPage, 'id'),- 'user_id' => data_get($oauthData, 'user_id'),- 'user_token' => data_get($oauthData, 'user_token'),+ $workspace->socialAccounts()->updateOrCreate(+ [+ 'platform' => $this->platform->value,+ 'platform_user_id' => data_get($selectedPage, 'id'),],- ]);+ [+ 'username' => data_get($selectedPage, 'username') ?? null,+ 'display_name' => data_get($selectedPage, 'name'),+ 'avatar_url' => $avatarPath,+ 'access_token' => data_get($selectedPage, 'access_token'),+ 'refresh_token' => null,+ 'token_expires_at' => null,+ 'scopes' => $this->scopes,+ 'status' => Status::Connected,+ 'error_message' => null,+ 'disconnected_at' => null,+ 'meta' => [+ 'page_id' => data_get($selectedPage, 'id'),+ 'user_id' => data_get($oauthData, 'user_id'),+ 'user_token' => data_get($oauthData, 'user_token'),+ ],+ ],+ );session()->forget(['facebook_oauth', 'social_reconnect_id']);diff --git a/app/Http/Controllers/Auth/InstagramController.php b/app/Http/Controllers/Auth/InstagramController.phpindex 2fdb5d945..b9379e152 100644--- a/app/Http/Controllers/Auth/InstagramController.php+++ b/app/Http/Controllers/Auth/InstagramController.php@@ -78,22 +78,27 @@ class InstagramController extends SocialController$expiresIn = $socialUser->expiresIn ?? 5184000; // 60 days in seconds$tokenExpiresAt = now()->addSeconds($expiresIn);- // Create new account- $workspace->socialAccounts()->create([- 'platform' => $this->platform->value,- 'platform_user_id' => $socialUser->getId(),- 'username' => $socialUser->getNickname(),- 'display_name' => $socialUser->getName() ?? $socialUser->getNickname(),- 'avatar_url' => $avatarPath,- 'access_token' => $socialUser->token,- 'refresh_token' => $socialUser->refreshToken,- 'token_expires_at' => $tokenExpiresAt,- 'scopes' => $this->scopes,- 'status' => Status::Connected,- 'meta' => [- 'account_type' => $socialUser->user['account_type'] ?? null,+ $workspace->socialAccounts()->updateOrCreate(+ [+ 'platform' => $this->platform->value,+ 'platform_user_id' => $socialUser->getId(),],- ]);+ [+ 'username' => $socialUser->getNickname(),+ 'display_name' => $socialUser->getName() ?? $socialUser->getNickname(),+ 'avatar_url' => $avatarPath,+ 'access_token' => $socialUser->token,+ 'refresh_token' => $socialUser->refreshToken,+ 'token_expires_at' => $tokenExpiresAt,+ 'scopes' => $this->scopes,+ 'status' => Status::Connected,+ 'error_message' => null,+ 'disconnected_at' => null,+ 'meta' => [+ 'account_type' => $socialUser->user['account_type'] ?? null,+ ],+ ],+ );return $this->popupCallback(true, 'Instagram account connected!', $this->platform->value);} catch (\Exception $e) {diff --git a/app/Http/Controllers/Auth/InstagramFacebookController.php b/app/Http/Controllers/Auth/InstagramFacebookController.phpindex 8480e8979..cc3fb1ed8 100644--- a/app/Http/Controllers/Auth/InstagramFacebookController.php+++ b/app/Http/Controllers/Auth/InstagramFacebookController.php@@ -218,10 +218,17 @@ class InstagramFacebookController extends SocialControllerreturn $this->popupCallback(true, 'Instagram account reconnected!', $this->platform->value);}- $account = $workspace->socialAccounts()->create(array_merge($accountData, [- 'platform' => $this->platform->value,- 'status' => Status::Connected,- ]));+ $account = $workspace->socialAccounts()->updateOrCreate(+ [+ 'platform' => $this->platform->value,+ 'platform_user_id' => data_get($pageData, 'ig_id'),+ ],+ array_merge($accountData, [+ 'status' => Status::Connected,+ 'error_message' => null,+ 'disconnected_at' => null,+ ]),+ );$isOnboarding = session('social_connect_onboarding', false);diff --git a/app/Http/Controllers/Auth/LinkedInController.php b/app/Http/Controllers/Auth/LinkedInController.phpindex 3d5f85afb..86239b662 100644--- a/app/Http/Controllers/Auth/LinkedInController.php+++ b/app/Http/Controllers/Auth/LinkedInController.php@@ -72,19 +72,24 @@ class LinkedInController extends SocialController$avatarPath = uploadFromUrl($socialUser->getAvatar());- // Create new account- $account = $workspace->socialAccounts()->create([- 'platform' => $this->platform->value,- 'platform_user_id' => $socialUser->getId(),- 'username' => $username,- 'display_name' => $socialUser->getName(),- 'avatar_url' => $avatarPath,- 'access_token' => $socialUser->token,- 'refresh_token' => $socialUser->refreshToken,- 'token_expires_at' => $socialUser->expiresIn ? now()->addSeconds($socialUser->expiresIn) : null,- 'scopes' => $socialUser->approvedScopes ?? null,- 'status' => Status::Connected,- ]);+ $account = $workspace->socialAccounts()->updateOrCreate(+ [+ 'platform' => $this->platform->value,+ 'platform_user_id' => $socialUser->getId(),+ ],+ [+ 'username' => $username,+ 'display_name' => $socialUser->getName(),+ 'avatar_url' => $avatarPath,+ 'access_token' => $socialUser->token,+ 'refresh_token' => $socialUser->refreshToken,+ 'token_expires_at' => $socialUser->expiresIn ? now()->addSeconds($socialUser->expiresIn) : null,+ 'scopes' => $socialUser->approvedScopes ?? null,+ 'status' => Status::Connected,+ 'error_message' => null,+ 'disconnected_at' => null,+ ],+ );// Sync tokens to LinkedIn Page if it existsapp(LinkedInTokenSynchronizer::class)->syncTokens($account);diff --git a/app/Http/Controllers/Auth/LinkedInPageController.php b/app/Http/Controllers/Auth/LinkedInPageController.phpindex 1d619815b..4d9514e23 100644--- a/app/Http/Controllers/Auth/LinkedInPageController.php+++ b/app/Http/Controllers/Auth/LinkedInPageController.php@@ -199,23 +199,28 @@ class LinkedInPageController extends SocialController}}- // Create new account- $account = $workspace->socialAccounts()->create([- 'platform' => $this->platform->value,- 'platform_user_id' => $request->organization_id,- 'username' => $request->organization_vanity_name,- 'display_name' => $request->organization_name,- 'avatar_url' => $avatarPath,- 'access_token' => $pendingData['token'],- 'refresh_token' => $pendingData['refresh_token'],- 'token_expires_at' => $pendingData['expires_in'] ? now()->addSeconds($pendingData['expires_in']) : null,- 'status' => Status::Connected,- 'meta' => [- 'organization_id' => $request->organization_id,- 'admin_user_id' => $pendingData['user_id'],- 'admin_name' => $pendingData['name'],+ $account = $workspace->socialAccounts()->updateOrCreate(+ [+ 'platform' => $this->platform->value,+ 'platform_user_id' => $request->organization_id,],- ]);+ [+ 'username' => $request->organization_vanity_name,+ 'display_name' => $request->organization_name,+ 'avatar_url' => $avatarPath,+ 'access_token' => $pendingData['token'],+ 'refresh_token' => $pendingData['refresh_token'],+ 'token_expires_at' => $pendingData['expires_in'] ? now()->addSeconds($pendingData['expires_in']) : null,+ 'status' => Status::Connected,+ 'error_message' => null,+ 'disconnected_at' => null,+ 'meta' => [+ 'organization_id' => $request->organization_id,+ 'admin_user_id' => $pendingData['user_id'],+ 'admin_name' => $pendingData['name'],+ ],+ ],+ );// Sync tokens to LinkedIn personal if it existsapp(LinkedInTokenSynchronizer::class)->syncTokens($account);diff --git a/app/Http/Controllers/Auth/MastodonController.php b/app/Http/Controllers/Auth/MastodonController.phpindex 9cb57679a..67edaffe2 100644--- a/app/Http/Controllers/Auth/MastodonController.php+++ b/app/Http/Controllers/Auth/MastodonController.php@@ -183,23 +183,28 @@ class MastodonController extends SocialController$avatarPath = data_get($profile, 'avatar') ? uploadFromUrl(data_get($profile, 'avatar')) : null;- // Create new account- $workspace->socialAccounts()->create([- 'platform' => $this->platform->value,- 'platform_user_id' => data_get($profile, 'id'),- 'username' => data_get($profile, 'acct'),- 'display_name' => data_get($profile, 'display_name') ?: data_get($profile, 'username'),- 'avatar_url' => $avatarPath,- 'access_token' => $accessToken,- 'refresh_token' => null, // Mastodon tokens don't expire- 'token_expires_at' => null,- 'status' => Status::Connected,- 'meta' => [- 'instance' => $instance,- 'client_id' => $clientId,- 'client_secret' => $clientSecret,+ $workspace->socialAccounts()->updateOrCreate(+ [+ 'platform' => $this->platform->value,+ 'platform_user_id' => data_get($profile, 'id'),],- ]);+ [+ 'username' => data_get($profile, 'acct'),+ 'display_name' => data_get($profile, 'display_name') ?: data_get($profile, 'username'),+ 'avatar_url' => $avatarPath,+ 'access_token' => $accessToken,+ 'refresh_token' => null,+ 'token_expires_at' => null,+ 'status' => Status::Connected,+ 'error_message' => null,+ 'disconnected_at' => null,+ 'meta' => [+ 'instance' => $instance,+ 'client_id' => $clientId,+ 'client_secret' => $clientSecret,+ ],+ ],+ );$this->clearMastodonSession();diff --git a/app/Http/Controllers/Auth/SocialController.php b/app/Http/Controllers/Auth/SocialController.phpindex 0502363fb..b687b5908 100644--- a/app/Http/Controllers/Auth/SocialController.php+++ b/app/Http/Controllers/Auth/SocialController.php@@ -159,19 +159,24 @@ class SocialController extends Controller$avatarPath = uploadFromUrl($socialUser->getAvatar());- // Create new account- $workspace->socialAccounts()->create([- 'platform' => $platform->value,- 'platform_user_id' => $socialUser->getId(),- 'username' => $socialUser->getNickname(),- 'display_name' => $socialUser->getName(),- 'avatar_url' => $avatarPath,- 'access_token' => $socialUser->token,- 'refresh_token' => $socialUser->refreshToken,- 'token_expires_at' => $socialUser->expiresIn ? now()->addSeconds($socialUser->expiresIn) : null,- 'scopes' => $socialUser->approvedScopes ?? null,- 'status' => Status::Connected,- ]);+ $workspace->socialAccounts()->updateOrCreate(+ [+ 'platform' => $platform->value,+ 'platform_user_id' => $socialUser->getId(),+ ],+ [+ 'username' => $socialUser->getNickname(),+ 'display_name' => $socialUser->getName(),+ 'avatar_url' => $avatarPath,+ 'access_token' => $socialUser->token,+ 'refresh_token' => $socialUser->refreshToken,+ 'token_expires_at' => $socialUser->expiresIn ? now()->addSeconds($socialUser->expiresIn) : null,+ 'scopes' => $socialUser->approvedScopes ?? null,+ 'status' => Status::Connected,+ 'error_message' => null,+ 'disconnected_at' => null,+ ],+ );return $this->popupCallback(true, 'Account connected!', $platform->value);} catch (\Exception $e) {diff --git a/app/Http/Controllers/Auth/ThreadsController.php b/app/Http/Controllers/Auth/ThreadsController.phpindex 624a165cb..86e2ff1e7 100644--- a/app/Http/Controllers/Auth/ThreadsController.php+++ b/app/Http/Controllers/Auth/ThreadsController.php@@ -136,19 +136,24 @@ class ThreadsController extends SocialController$profile = $profileResponse->json();$avatarPath = uploadFromUrl(data_get($profile, 'threads_profile_picture_url', null));- // Create new account- $workspace->socialAccounts()->create([- 'platform' => $this->platform->value,- 'platform_user_id' => data_get($profile, 'id'),- 'username' => data_get($profile, 'username'),- 'display_name' => data_get($profile, 'name', data_get($profile, 'username')),- 'avatar_url' => $avatarPath,- 'access_token' => $longLivedToken,- 'refresh_token' => null,- 'token_expires_at' => $expiresIn ? now()->addSeconds($expiresIn) : null,- 'scopes' => $this->scopes,- 'status' => Status::Connected,- ]);+ $workspace->socialAccounts()->updateOrCreate(+ [+ 'platform' => $this->platform->value,+ 'platform_user_id' => data_get($profile, 'id'),+ ],+ [+ 'username' => data_get($profile, 'username'),+ 'display_name' => data_get($profile, 'name', data_get($profile, 'username')),+ 'avatar_url' => $avatarPath,+ 'access_token' => $longLivedToken,+ 'refresh_token' => null,+ 'token_expires_at' => $expiresIn ? now()->addSeconds($expiresIn) : null,+ 'scopes' => $this->scopes,+ 'status' => Status::Connected,+ 'error_message' => null,+ 'disconnected_at' => null,+ ],+ );session()->forget(['threads_oauth_state', 'social_reconnect_id']);diff --git a/app/Http/Controllers/Auth/TikTokController.php b/app/Http/Controllers/Auth/TikTokController.phpindex 04bdea5fc..e0920f0f9 100644--- a/app/Http/Controllers/Auth/TikTokController.php+++ b/app/Http/Controllers/Auth/TikTokController.php@@ -75,19 +75,24 @@ class TikTokController extends SocialController$username = $socialUser->getNickname();$avatarPath = uploadFromUrl($socialUser->getAvatar());- // Create new account- $workspace->socialAccounts()->create([- 'platform' => $this->platform->value,- 'platform_user_id' => $socialUser->getId(),- 'username' => $username,- 'display_name' => $socialUser->getName(),- 'avatar_url' => $avatarPath,- 'access_token' => $socialUser->token,- 'refresh_token' => $socialUser->refreshToken,- 'token_expires_at' => $socialUser->expiresIn ? now()->addSeconds($socialUser->expiresIn) : null,- 'scopes' => $socialUser->approvedScopes ?? null,- 'status' => Status::Connected,- ]);+ $workspace->socialAccounts()->updateOrCreate(+ [+ 'platform' => $this->platform->value,+ 'platform_user_id' => $socialUser->getId(),+ ],+ [+ 'username' => $username,+ 'display_name' => $socialUser->getName(),+ 'avatar_url' => $avatarPath,+ 'access_token' => $socialUser->token,+ 'refresh_token' => $socialUser->refreshToken,+ 'token_expires_at' => $socialUser->expiresIn ? now()->addSeconds($socialUser->expiresIn) : null,+ 'scopes' => $socialUser->approvedScopes ?? null,+ 'status' => Status::Connected,+ 'error_message' => null,+ 'disconnected_at' => null,+ ],+ );session()->forget('social_reconnect_id');diff --git a/app/Http/Controllers/Auth/YouTubeController.php b/app/Http/Controllers/Auth/YouTubeController.phpindex f574fbcfd..b6a27f9ad 100644--- a/app/Http/Controllers/Auth/YouTubeController.php+++ b/app/Http/Controllers/Auth/YouTubeController.php@@ -80,23 +80,28 @@ class YouTubeController extends SocialController$channel = $channels[0];$avatarPath = uploadFromUrl(data_get($channel, 'thumbnail'));- // Create new account- $workspace->socialAccounts()->create([- 'platform' => $this->platform->value,- 'platform_user_id' => data_get($channel, 'id'),- 'username' => ltrim(data_get($channel, 'custom_url', data_get($channel, 'id')), '@'),- 'display_name' => data_get($channel, 'title'),- 'avatar_url' => $avatarPath,- 'access_token' => $socialUser->token,- 'refresh_token' => $socialUser->refreshToken,- 'token_expires_at' => $socialUser->expiresIn ? now()->addSeconds($socialUser->expiresIn) : null,- 'scopes' => $this->scopes,- 'status' => Status::Connected,- 'meta' => [- 'channel_id' => data_get($channel, 'id'),- 'google_user_id' => $socialUser->getId(),+ $workspace->socialAccounts()->updateOrCreate(+ [+ 'platform' => $this->platform->value,+ 'platform_user_id' => data_get($channel, 'id'),],- ]);+ [+ 'username' => ltrim(data_get($channel, 'custom_url', data_get($channel, 'id')), '@'),+ 'display_name' => data_get($channel, 'title'),+ 'avatar_url' => $avatarPath,+ 'access_token' => $socialUser->token,+ 'refresh_token' => $socialUser->refreshToken,+ 'token_expires_at' => $socialUser->expiresIn ? now()->addSeconds($socialUser->expiresIn) : null,+ 'scopes' => $this->scopes,+ 'status' => Status::Connected,+ 'error_message' => null,+ 'disconnected_at' => null,+ 'meta' => [+ 'channel_id' => data_get($channel, 'id'),+ 'google_user_id' => $socialUser->getId(),+ ],+ ],+ );return $this->popupCallback(true, 'YouTube channel connected!', $this->platform->value);}@@ -220,23 +225,28 @@ class YouTubeController extends SocialController}}- // Create new account- $workspace->socialAccounts()->create([- 'platform' => $this->platform->value,- 'platform_user_id' => data_get($selectedChannel, 'id'),- 'username' => ltrim(data_get($selectedChannel, 'custom_url', data_get($selectedChannel, 'id')), '@'),- 'display_name' => data_get($selectedChannel, 'title'),- 'avatar_url' => $avatarPath,- 'access_token' => data_get($oauthData, 'access_token'),- 'refresh_token' => data_get($oauthData, 'refresh_token'),- 'token_expires_at' => data_get($oauthData, 'expires_in') ? now()->addSeconds(data_get($oauthData, 'expires_in')) : null,- 'scopes' => $this->scopes,- 'status' => Status::Connected,- 'meta' => [- 'channel_id' => data_get($selectedChannel, 'id'),- 'google_user_id' => data_get($oauthData, 'user_id'),+ $workspace->socialAccounts()->updateOrCreate(+ [+ 'platform' => $this->platform->value,+ 'platform_user_id' => data_get($selectedChannel, 'id'),],- ]);+ [+ 'username' => ltrim(data_get($selectedChannel, 'custom_url', data_get($selectedChannel, 'id')), '@'),+ 'display_name' => data_get($selectedChannel, 'title'),+ 'avatar_url' => $avatarPath,+ 'access_token' => data_get($oauthData, 'access_token'),+ 'refresh_token' => data_get($oauthData, 'refresh_token'),+ 'token_expires_at' => data_get($oauthData, 'expires_in') ? now()->addSeconds(data_get($oauthData, 'expires_in')) : null,+ 'scopes' => $this->scopes,+ 'status' => Status::Connected,+ 'error_message' => null,+ 'disconnected_at' => null,+ 'meta' => [+ 'channel_id' => data_get($selectedChannel, 'id'),+ 'google_user_id' => data_get($oauthData, 'user_id'),+ ],+ ],+ );session()->forget(['youtube_oauth', 'social_reconnect_id']);diff --git a/app/Services/Social/FacebookAnalytics.php b/app/Services/Social/FacebookAnalytics.phpindex 5f2de38ab..ccb6f82b7 100644--- a/app/Services/Social/FacebookAnalytics.php+++ b/app/Services/Social/FacebookAnalytics.php@@ -15,7 +15,7 @@ class FacebookAnalytics{use HasSocialHttpClient;- private string $baseUrl = 'https://graph.facebook.com/v20.0';+ private string $baseUrl = 'https://graph.facebook.com/v25.0';private string $accessToken;@@ -38,7 +38,7 @@ class FacebookAnalytics$response = $this->getHttpClient()->get("{$this->baseUrl}/{$account->platform_user_id}/insights", [- 'metric' => 'page_impressions_unique,page_posts_impressions_unique,page_post_engagements,page_daily_follows,page_video_views',+ 'metric' => 'page_total_media_view_unique,post_total_media_view_unique,page_post_engagements,page_daily_follows,page_media_view','period' => 'day','since' => $since->startOfDay()->unix(),'until' => $until->endOfDay()->unix(),@@ -67,11 +67,11 @@ class FacebookAnalytics$total = collect($values)->sum('value');$label = match ($name) {- 'page_impressions_unique' => 'Page Impressions',- 'page_posts_impressions_unique' => 'Posts Impressions',+ 'page_total_media_view_unique' => 'Page Reach',+ 'post_total_media_view_unique' => 'Posts Reach','page_post_engagements' => 'Posts Engagement','page_daily_follows' => 'Page Followers',- 'page_video_views' => 'Video Views',+ 'page_media_view' => 'Page Views',default => ucfirst(str_replace('_', ' ', $name)),};diff --git a/app/Services/Social/XAnalytics.php b/app/Services/Social/XAnalytics.phpindex d5b0860f4..2af588e3d 100644--- a/app/Services/Social/XAnalytics.php+++ b/app/Services/Social/XAnalytics.php@@ -160,11 +160,13 @@ class XAnalyticsthrow new TokenExpiredException('No refresh token available for X account');}- $response = $this->socialHttp()->asForm()->post('https://api.x.com/2/oauth2/token', [- 'grant_type' => 'refresh_token',- 'refresh_token' => $account->refresh_token,- 'client_id' => config('services.x.client_id'),- ]);+ $response = $this->socialHttp()+ ->withBasicAuth(config('services.x.client_id'), config('services.x.client_secret'))+ ->asForm()+ ->post('https://api.x.com/2/oauth2/token', [+ 'grant_type' => 'refresh_token',+ 'refresh_token' => $account->refresh_token,+ ]);if ($response->failed()) {Log::error('X token refresh failed', ['body' => $this->redactResponseBody($response->body())]);diff --git a/resources/js/pages/settings/Account.vue b/resources/js/pages/settings/Account.vueindex 9b6ded68f..fe07edc20 100644--- a/resources/js/pages/settings/Account.vue+++ b/resources/js/pages/settings/Account.vue@@ -18,8 +18,9 @@ interface AccountData {billing_email: string;}-defineProps<{+const props = defineProps<{account: AccountData;+ selfHosted: boolean;}>();const breadcrumbItems = computed<BreadcrumbItem[]>(() => [@@ -54,7 +55,7 @@ const breadcrumbItems = computed<BreadcrumbItem[]>(() => [<InputError :message="errors.name" /></div>- <div class="grid gap-2">+ <div v-if="!selfHosted" class="grid gap-2"><Label for="billing-email">{{ $t('settings.account.billing_email') }}</Label><Inputid="billing-email"diff --git a/tests/Feature/AccountControllerTest.php b/tests/Feature/AccountControllerTest.phpnew file mode 100644index 000000000..5c4aa5944--- /dev/null+++ b/tests/Feature/AccountControllerTest.php@@ -0,0 +1,87 @@+<?php++declare(strict_types=1);++use App\Enums\User\Setup;+use App\Enums\UserWorkspace\Role;+use App\Models\Account;+use App\Models\User;+use App\Models\Workspace;++beforeEach(function () {+ $this->account = Account::factory()->create();+ $this->user = User::factory()->create([+ 'setup' => Setup::Completed,+ 'account_id' => $this->account->id,+ ]);+ $this->account->update(['owner_id' => $this->user->id]);+ $this->workspace = Workspace::factory()->create([+ 'account_id' => $this->account->id,+ 'user_id' => $this->user->id,+ ]);+ $this->workspace->members()->attach($this->user->id, ['role' => Role::Member->value]);+ $this->user->update(['current_workspace_id' => $this->workspace->id]);+});++test('account edit shows account settings with billing email when not self hosted', function () {+ config(['trypost.self_hosted' => false]);++ $this->account->subscriptions()->create([+ 'type' => Account::SUBSCRIPTION_NAME,+ 'stripe_id' => 'sub_test_'.fake()->uuid(),+ 'stripe_status' => 'active',+ 'stripe_price' => 'price_123',+ ]);++ $response = $this->actingAs($this->user)->get(route('app.account.edit'));++ $response->assertOk();+ $response->assertInertia(fn ($page) => $page+ ->component('settings/Account', false)+ ->where('selfHosted', false)+ ->has('account.billing_email')+ );+});++test('account edit shows self hosted flag when self hosted', function () {+ config(['trypost.self_hosted' => true]);++ $response = $this->actingAs($this->user)->get(route('app.account.edit'));++ $response->assertOk();+ $response->assertInertia(fn ($page) => $page+ ->component('settings/Account', false)+ ->where('selfHosted', true)+ );+});++test('account update does not require billing email when self hosted', function () {+ config(['trypost.self_hosted' => true]);++ $response = $this->actingAs($this->user)->put(route('app.account.update'), [+ 'name' => 'Updated Account',+ ]);++ $response->assertRedirect();+ $this->assertDatabaseHas('accounts', [+ 'id' => $this->account->id,+ 'name' => 'Updated Account',+ ]);+});++test('account update requires billing email when not self hosted', function () {+ config(['trypost.self_hosted' => false]);++ $this->account->subscriptions()->create([+ 'type' => Account::SUBSCRIPTION_NAME,+ 'stripe_id' => 'sub_test_'.fake()->uuid(),+ 'stripe_status' => 'active',+ 'stripe_price' => 'price_123',+ ]);++ $response = $this->actingAs($this->user)->put(route('app.account.update'), [+ 'name' => 'Updated Account',+ ]);++ $response->assertSessionHasErrors('billing_email');+});diff --git a/tests/Feature/BillingControllerTest.php b/tests/Feature/BillingControllerTest.phpindex e50622200..d80931295 100644--- a/tests/Feature/BillingControllerTest.php+++ b/tests/Feature/BillingControllerTest.php@@ -45,6 +45,8 @@ test('subscribe shows subscription page', function () {});test('subscribe redirects to billing index when account has active subscription', function () {+ config(['trypost.self_hosted' => false]);+$this->account->subscriptions()->create(['type' => Account::SUBSCRIPTION_NAME,'stripe_id' => 'sub_test_'.fake()->uuid(),@@ -57,6 +59,14 @@ test('subscribe redirects to billing index when account has active subscription'$response->assertRedirect(route('app.billing.index'));});+test('subscribe redirects to calendar in self hosted mode', function () {+ config(['trypost.self_hosted' => true]);++ $response = $this->actingAs($this->user)->get(route('app.subscribe'));++ $response->assertRedirect(route('app.calendar'));+});+// Index teststest('billing index requires authentication', function () {$response = $this->get(route('app.billing.index'));@@ -65,6 +75,8 @@ test('billing index requires authentication', function () {});test('billing index shows billing dashboard', function () {+ config(['trypost.self_hosted' => false]);+$this->account->subscriptions()->create(['type' => Account::SUBSCRIPTION_NAME,'stripe_id' => 'sub_test_'.fake()->uuid(),@@ -83,6 +95,14 @@ test('billing index shows billing dashboard', function () {);});+test('billing index redirects to calendar in self hosted mode', function () {+ config(['trypost.self_hosted' => true]);++ $response = $this->actingAs($this->user)->get(route('app.billing.index'));++ $response->assertRedirect(route('app.calendar'));+});+// Processing teststest('billing processing requires authentication', function () {$response = $this->get(route('app.billing.processing'));@@ -91,6 +111,8 @@ test('billing processing requires authentication', function () {});test('billing processing shows processing page', function () {+ config(['trypost.self_hosted' => false]);+$response = $this->actingAs($this->user)->get(route('app.billing.processing'));$response->assertOk();@@ -100,6 +122,13 @@ test('billing processing shows processing page', function () {);});+test('billing processing redirects to calendar in self hosted mode', function () {+ config(['trypost.self_hosted' => true]);++ $response = $this->actingAs($this->user)->get(route('app.billing.processing'));++ $response->assertRedirect(route('app.calendar'));+});// Checkout teststest('checkout requires authentication', function () {@@ -118,6 +147,8 @@ test('portal requires authentication', function () {// Authorization teststest('non-owner admin cannot access billing index', function () {+ config(['trypost.self_hosted' => false]);+$admin = User::factory()->create(['setup' => Setup::Completed,'account_id' => $this->account->id,@@ -136,6 +167,8 @@ test('non-owner admin cannot access billing index', function () {});test('member cannot access billing index', function () {+ config(['trypost.self_hosted' => false]);+$member = User::factory()->create(['setup' => Setup::Completed,'account_id' => $this->account->id,diff --git a/tests/Feature/UsageControllerTest.php b/tests/Feature/UsageControllerTest.phpnew file mode 100644index 000000000..db573339e--- /dev/null+++ b/tests/Feature/UsageControllerTest.php@@ -0,0 +1,51 @@+<?php++declare(strict_types=1);++use App\Enums\User\Setup;+use App\Enums\UserWorkspace\Role;+use App\Models\Account;+use App\Models\User;+use App\Models\Workspace;++beforeEach(function () {+ $this->account = Account::factory()->create();+ $this->user = User::factory()->create([+ 'setup' => Setup::Completed,+ 'account_id' => $this->account->id,+ ]);+ $this->account->update(['owner_id' => $this->user->id]);+ $this->workspace = Workspace::factory()->create([+ 'account_id' => $this->account->id,+ 'user_id' => $this->user->id,+ ]);+ $this->workspace->members()->attach($this->user->id, ['role' => Role::Member->value]);+ $this->user->update(['current_workspace_id' => $this->workspace->id]);+});++test('usage index redirects to calendar in self hosted mode', function () {+ config(['trypost.self_hosted' => true]);++ $response = $this->actingAs($this->user)->get(route('app.usage.index'));++ $response->assertRedirect(route('app.calendar'));+});++test('usage index shows usage page when not self hosted', function () {+ config(['trypost.self_hosted' => false]);++ $this->account->subscriptions()->create([+ 'type' => Account::SUBSCRIPTION_NAME,+ 'stripe_id' => 'sub_test_'.fake()->uuid(),+ 'stripe_status' => 'active',+ 'stripe_price' => 'price_123',+ ]);++ $response = $this->actingAs($this->user)->get(route('app.usage.index'));++ $response->assertOk();+ $response->assertInertia(fn ($page) => $page+ ->component('settings/Usage', false)+ ->has('usage')+ );+});