优化 Request 认证

This commit is contained in:
JaguarJack 2020-07-13 17:07:18 +08:00
parent 19c092dffc
commit 32b87baeee

View File

@ -14,20 +14,21 @@ class Request extends \think\Request
{ {
protected $auth; protected $auth;
/** /**
* login user * login user
* *
* @time 2020年01月09日 * @time 2020年01月09日
* @return mixed * @param null $guard
*/ * @return mixed
public function user() */
public function user($guard = null)
{ {
if (!$this->auth) { if (!$this->auth) {
$this->auth = new CatchAuth; $this->auth = new CatchAuth;
} }
try { try {
$user = $this->auth->user(); $user = $this->auth->guard($guard ? : config('catch.auth.default.guard'))->user();
} catch (\Exception $e) { } catch (\Exception $e) {
if ($e instanceof TokenExpiredException) { if ($e instanceof TokenExpiredException) {
throw new FailedException('token 过期', Code::LOGIN_EXPIRED); throw new FailedException('token 过期', Code::LOGIN_EXPIRED);