优化 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;
/**
* login user
*
* @time 2020年01月09日
* @return mixed
*/
public function user()
/**
* login user
*
* @time 2020年01月09日
* @param null $guard
* @return mixed
*/
public function user($guard = null)
{
if (!$this->auth) {
$this->auth = new CatchAuth;
}
try {
$user = $this->auth->user();
$user = $this->auth->guard($guard ? : config('catch.auth.default.guard'))->user();
} catch (\Exception $e) {
if ($e instanceof TokenExpiredException) {
throw new FailedException('token 过期', Code::LOGIN_EXPIRED);