优化 Request 认证

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

View File

@ -18,16 +18,17 @@ class Request extends \think\Request
* login user
*
* @time 2020年01月09日
* @param null $guard
* @return mixed
*/
public function user()
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);