File tree 2 files changed +27
-0
lines changed
2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ class Kernel extends HttpKernel
41
41
Tracking::class,
42
42
Middleware \CheckIfUserBanned::class,
43
43
Middleware \OTP ::class,
44
+ Middleware \LoginRedirect::class,
44
45
],
45
46
46
47
'api ' => [
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments