Skip to content

Commit

Permalink
fix: #78 fix subscription middleware logic
Browse files Browse the repository at this point in the history
  • Loading branch information
bohdan-shulha committed Aug 4, 2024
1 parent 486434f commit 53645d9
Show file tree
Hide file tree
Showing 6 changed files with 429 additions and 133 deletions.
2 changes: 2 additions & 0 deletions app/Actions/Fortify/CreateNewUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ protected function createTeam(User $user): void
'user_id' => $user->id,
'name' => explode(' ', $user->name, 2)[0]."'s Team",
'personal_team' => true,
'billing_email' => $user->email,
'billing_name' => $user->name,
]));
}
}
6 changes: 1 addition & 5 deletions app/Http/Middleware/EnsureTeamSubscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@ class EnsureTeamSubscription
*/
public function handle(Request $request, Closure $next): Response
{
if (auth()->guest()) {
return $next($request);
}

$team = auth()->user()->currentTeam;
$subscription = $team->subscription();

$doesntHaveSubscription = $subscription === null || ! $subscription->onTrial() && ! $subscription->active();
if ($doesntHaveSubscription && ! $request->routeIs('teams.billing.show')) {
if ($doesntHaveSubscription) {
return redirect()->route('teams.billing.show', $team);
}

Expand Down
3 changes: 0 additions & 3 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use ApiNodes\Http\Middleware\AgentTokenAuth;
use App\Console\Commands\DispatchProcessBackupTask;
use App\Console\Commands\DispatchVolumeBackupTask;
use App\Http\Middleware\EnsureTeamSubscription;
use App\Http\Middleware\HandleInertiaRequests;
use App\Jobs\CheckAgentUpdates;
use App\Models\Service;
Expand Down Expand Up @@ -32,12 +31,10 @@
$middleware
->api(prepend: [
AgentTokenAuth::class,
EnsureTeamSubscription::class,
])
->web(append: [
HandleInertiaRequests::class,
AddLinkHeadersForPreloadedAssets::class,
EnsureTeamSubscription::class,
])
->alias([
'abilities' => CheckAbilities::class,
Expand Down
Loading

0 comments on commit 53645d9

Please sign in to comment.