Browse Source

Merge pull request #2063 from visuddhinanda/laravel

role为空 返回[]
visuddhinanda 2 years ago
parent
commit
4d058f9474
1 changed files with 10 additions and 1 deletions
  1. 10 1
      app/Http/Controllers/AuthController.php

+ 10 - 1
app/Http/Controllers/AuthController.php

@@ -106,9 +106,18 @@ class AuthController extends Controller
             "nickName"=> $userInfo->nickname,
             "nickName"=> $userInfo->nickname,
             "realName"=> $userInfo->username,
             "realName"=> $userInfo->username,
             "avatar"=> "",
             "avatar"=> "",
-            "roles"=> json_decode($userInfo->role),
             "token"=>\substr($request->header('Authorization'),7) ,
             "token"=>\substr($request->header('Authorization'),7) ,
         ];
         ];
+
+        //role为空 返回[]
+        $user['roles'] = [];
+        if(!empty($userInfo->role)){
+            $roles = json_decode($userInfo->role);
+            if(is_array($roles)){
+                $user['roles'] = $roles;
+            }
+        }
+
         if($curr['user_uid'] === config('mint.admin.root_uuid')){
         if($curr['user_uid'] === config('mint.admin.root_uuid')){
             $user['roles'] = ['root'];
             $user['roles'] = ['root'];
         }
         }