<?php

namespace App\Http\Middleware;

use Exception;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Event;
use Throwable;

class AuthMiddleware{

	public function handle(Request $request, \Closure $next, ...$guards){
		try {
			if (! $user = Auth::guard($guards)->user()) {
				throw new AuthenticationException();
			}
			return $next($request);
		} catch (Exception|Throwable $e) {
			return response()->json(['code' => 2000, 'message' => '请重新登录！']);
		}
	}
}
