1<?php
2
3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4// See the LICENCE file in the repository root for full licence text.
5
6namespace App\Http\Middleware;
7
8use Closure;
9use Illuminate\Contracts\Auth\Guard;
10use Session;
11
12class RedirectIfAuthenticated
13{
14 /**
15 * The Guard implementation.
16 *
17 * @var Guard
18 */
19 protected $auth;
20
21 /**
22 * Create a new filter instance.
23 *
24 * @param Guard $auth
25 *
26 * @return void
27 */
28 public function __construct(Guard $auth)
29 {
30 $this->auth = $auth;
31 }
32
33 /**
34 * Handle an incoming request.
35 *
36 * @param \Illuminate\Http\Request $request
37 * @param \Closure $next
38 *
39 * @return mixed
40 */
41 public function handle($request, Closure $next)
42 {
43 if ($this->auth->check()) {
44 return redirect(Session::pull('last-successful-page', '/'));
45 }
46
47 return $next($request);
48 }
49}