Skip to content

Commit 2b21300

Browse files
committed
fix(auth): redirect user function his role
1 parent cbfbdb7 commit 2b21300

File tree

5 files changed

+87
-6
lines changed

5 files changed

+87
-6
lines changed

app/Http/Controllers/Auth/AuthenticatedSessionController.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ public function store(LoginRequest $request): RedirectResponse
3333

3434
$request->session()->regenerate();
3535

36-
return redirect()->intended(route('dashboard', absolute: false));
36+
if (Auth::user()->is_admin)
37+
{
38+
return redirect()->intended(route('dashboard', absolute: false));
39+
}
40+
41+
return redirect()->intended(route('chat.index', absolute: false));
3742
}
3843

3944
/**

app/Http/Controllers/Auth/RegisteredUserController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ public function store(Request $request): RedirectResponse
4646

4747
Auth::login($user);
4848

49-
return to_route('dashboard');
49+
return to_route('chat.index');
5050
}
5151
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Web;
4+
5+
use App\Http\Controllers\Controller;
6+
use Illuminate\Http\Request;
7+
8+
class ChatController extends Controller
9+
{
10+
/**
11+
* Display a listing of the resource.
12+
*/
13+
public function index()
14+
{
15+
//
16+
}
17+
18+
/**
19+
* Show the form for creating a new resource.
20+
*/
21+
public function create()
22+
{
23+
//
24+
}
25+
26+
/**
27+
* Store a newly created resource in storage.
28+
*/
29+
public function store(Request $request)
30+
{
31+
//
32+
}
33+
34+
/**
35+
* Display the specified resource.
36+
*/
37+
public function show(string $id)
38+
{
39+
//
40+
}
41+
42+
/**
43+
* Show the form for editing the specified resource.
44+
*/
45+
public function edit(string $id)
46+
{
47+
//
48+
}
49+
50+
/**
51+
* Update the specified resource in storage.
52+
*/
53+
public function update(Request $request, string $id)
54+
{
55+
//
56+
}
57+
58+
/**
59+
* Remove the specified resource from storage.
60+
*/
61+
public function destroy(string $id)
62+
{
63+
//
64+
}
65+
}

bootstrap/app.php

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
HandleInertiaRequests::class,
1919
AddLinkHeadersForPreloadedAssets::class,
2020
]);
21+
$middleware->alias(
22+
[
23+
'admin' => \App\Http\Middleware\AdminMiddleware::class,
24+
]
25+
);
2126
})
2227
->withExceptions(function (Exceptions $exceptions) {
2328
//

routes/web.php

+10-4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@
77
return Inertia::render('welcome');
88
})->name('home');
99

10-
Route::middleware(['auth', 'verified', \App\Http\Middleware\AdminMiddleware::class])->group(function () {
11-
Route::get('dashboard', function () {
12-
return Inertia::render('dashboard');
13-
})->name('dashboard');
10+
Route::middleware(['auth', 'verified'])->group(function () {
11+
12+
Route::get('chat', [\App\Http\Controllers\Web\ChatController::class, 'index'])->name('chat.index');
13+
14+
Route::middleware(['admin'])->group(function () {
15+
Route::get('dashboard', function () {
16+
return Inertia::render('dashboard');
17+
})->name('dashboard');
18+
});
1419
});
1520

21+
1622
require __DIR__.'/settings.php';
1723
require __DIR__.'/auth.php';

0 commit comments

Comments
 (0)