59 lines
1.8 KiB
PHP
59 lines
1.8 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Middleware;
|
||
|
|
|
||
|
|
use App\Models\BirzhaUser;
|
||
|
|
use Closure;
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
use Inertia\Inertia;
|
||
|
|
use Throwable;
|
||
|
|
|
||
|
|
class CheckOctoberSession
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Handle an incoming request.
|
||
|
|
*
|
||
|
|
* @param \Illuminate\Http\Request $request
|
||
|
|
* @param \Closure $next
|
||
|
|
* @return mixed
|
||
|
|
*/
|
||
|
|
public function handle(Request $request, Closure $next)
|
||
|
|
{
|
||
|
|
// $url = url()->previous();
|
||
|
|
// $route = app('router')->getRoutes($url)->match(app('request')->create($url))->getName();
|
||
|
|
// dd($route);
|
||
|
|
// For Admin's session
|
||
|
|
if(\Auth::check()) {
|
||
|
|
return $next($request);
|
||
|
|
}
|
||
|
|
|
||
|
|
// For Birzha User's session
|
||
|
|
try{
|
||
|
|
if(env('APP_ENV') == 'production') {
|
||
|
|
$userId = preg_split("/[\s\[\]\",]+/", \Cookie::get('user_auth'))[1];
|
||
|
|
|
||
|
|
$user = BirzhaUser::find($userId);
|
||
|
|
|
||
|
|
if(is_null($user)) {
|
||
|
|
// if($route == 'logout') return Inertia::location(env('PARENT_APP'));
|
||
|
|
// return Inertia::location(env('PARENT_APP'));
|
||
|
|
return redirect()->away(env('PARENT_APP'));
|
||
|
|
} else {
|
||
|
|
return $next($request);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
// if($route == 'logout') return Inertia::location(env('PARENT_APP'));
|
||
|
|
// return Inertia::location(env('PARENT_APP'));
|
||
|
|
return redirect()->away(env('PARENT_APP'));
|
||
|
|
}
|
||
|
|
} catch(Throwable $th) {
|
||
|
|
\Log::info($th);
|
||
|
|
|
||
|
|
// if($route == 'logout') return Inertia::location(env('PARENT_APP'));
|
||
|
|
// return Inertia::location(env('PARENT_APP'));
|
||
|
|
return redirect()->away(env('PARENT_APP'));
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|