Skip to content

Commit 713792b

Browse files
committed
Redirect to roadmap
1 parent 5a4f4c8 commit 713792b

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

app/Http/Kernel.php

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class Kernel extends HttpKernel
4141
Tracking::class,
4242
Middleware\CheckIfUserBanned::class,
4343
Middleware\OTP::class,
44+
Middleware\LoginRedirect::class,
4445
],
4546

4647
'api' => [

app/Http/Middleware/LoginRedirect.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace App\Http\Middleware;
4+
5+
use Symfony\Component\HttpFoundation\Response;
6+
use Illuminate\Http\Request;
7+
use Closure;
8+
9+
class LoginRedirect
10+
{
11+
public function handle(Request $request, Closure $next): Response
12+
{
13+
// Store the previous URL in session only if it's not the login route itself and is a valid redirect url
14+
if ($request->is('login') || $request->is('register')) {
15+
//If to check where the request is coming from and set the variable if its a valid route.
16+
if (url()->previous() === route('roadmap')) {
17+
session(['login_redirect' => url()->previous()]);
18+
} elseif (!(url()->previous() === route('login')) && !(url()->previous() === route('register'))) {
19+
//If the user moves outside the login page, reset the redirect variable.
20+
session(['login_redirect' => null]);
21+
}
22+
}
23+
24+
return $next($request);
25+
}
26+
}

0 commit comments

Comments
 (0)