12345678910111213141516171819202122232425262728293031 |
- <?php
- namespace App\Http\Middleware;
- use App\Models\User\User;
- use App\Modules\Admin\Services\AuthService;
- use Closure;
- use Illuminate\Auth\AuthenticationException;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Auth;
- class AuthLoginMiddleware
- {
- public function handle(Request $request, Closure $next)
- {
- $token = $request->header('Authorization');
- if (empty($token)) {
- return $next($request);
- }
- $uid = app(AuthService::class)->decryptToken(substr($token, 7));
- $u = User::find($uid);
- if ($u) {
- Auth::login($u);
- }
- return $next($request);
- }
- }
|