Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict for DevDojo Auth Setup to Admin users #177

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class Kernel extends HttpKernel
* @var array<string, class-string|string>
*/
protected $routeMiddleware = [
'admin' => \App\Http\Middleware\AdminOnlyRoutes::class,
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class,
Expand Down
25 changes: 25 additions & 0 deletions app/Http/Middleware/AdminOnlyRoutes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class AdminOnlyRoutes
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
if ($request->user() && $request->user()->hasRole('admin')) {
return $next($request);
}

abort(403);
}
}
7 changes: 7 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@

// Wave routes
Wave::routes();

// Restriction for DevDojo Auth Setup - Restrict /auth/setup/* to admin users only
Route::group(['prefix' => 'auth/setup', 'middleware' => ['auth', 'admin']], function () {
Route::any('{any}', function () {
return view('wave::auth.setup'); // Replace with the appropriate view or logic
})->where('any', '.*'); // Wildcard to match anything after /auth/setup/
});
Loading