Skip to content

Commit

Permalink
Add toast
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell committed Nov 23, 2023
1 parent fb80ec2 commit 1bce2dc
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Http/Middleware/CP/RedirectIfAuthorized.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Statamic\Http\Middleware\CP;

use Closure;
use Statamic\Facades\CP\Toast;
use Statamic\Facades\User;

class RedirectIfAuthorized
Expand All @@ -17,7 +18,13 @@ class RedirectIfAuthorized
public function handle($request, Closure $next, $guard = null)
{
if ($user = User::current()) {
return redirect($user->can('access cp') ? cp_route('index') : '/');
if ($user->can('access cp')) {
Toast::error(__('You can\'t do this while logged in'));

return redirect(cp_route('index'));
}

return redirect('/');
}

return $next($request);
Expand Down

0 comments on commit 1bce2dc

Please sign in to comment.