mirror of
https://github.com/henrywhitaker3/Speedtest-Tracker.git
synced 2025-12-25 23:03:36 +01:00
Added base app
Has basic login UI, has methods to run speedtests
This commit is contained in:
39
app/Http/Middleware/CheckActiveSession.php
Normal file
39
app/Http/Middleware/CheckActiveSession.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Auth\LoginSession;
|
||||
use Closure;
|
||||
use Exception;
|
||||
|
||||
class CheckActiveSession
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
try {
|
||||
$token = $request->bearerToken();
|
||||
if($token == null) { $token = $request->token; }
|
||||
$session = LoginSession::where('token', $token)
|
||||
->first();
|
||||
|
||||
if(!$session->active) {
|
||||
return response()->json([
|
||||
'error' => 'token is invalid'
|
||||
], 401);
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
return response()->json([
|
||||
'error' => 'token not found'
|
||||
], 401);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user