<?php

namespace App\Http\Middleware;

use Closure;

/**
 * Class Authentication
 *
 * Copyright (C) 2018 buduxs. All rights reserved.
 * @author  Omair Saleh <uldvstar@gmail.com>
 * @license Proprietary
 */
class Authentication {
    /**
     * Handle an incoming request.
     *
     * @param \Illuminate\Http\Request $request
     * @param \Closure                 $next
     *
     * @return mixed
     */
    public function handle($request, Closure $next) {
        // if the session does not contain the token, redirect back to the login
        if (auth()->check() === false) {
            return redirect()->route('login')->withErrors('Your session has expired. Please log in again.');
        }

        return $next($request);
    }
}
