fix: offcava
This commit is contained in:
@@ -8,6 +8,7 @@ use Illuminate\Support\Facades\Hash;
|
||||
use Tymon\JWTAuth\Facades\JWTAuth;
|
||||
use Tymon\JWTAuth\Exceptions\JWTException;
|
||||
use App\Http\Requests\LoginRequest;
|
||||
use App\Models\Video;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
@@ -47,15 +48,15 @@ class AuthController extends Controller
|
||||
"password" => $request->password
|
||||
]);
|
||||
|
||||
if(!$login) {
|
||||
if (!$login) {
|
||||
return response()->json([
|
||||
'message' => 'Credenciais inválidas',
|
||||
'errors' => null,
|
||||
], 400);
|
||||
], 400);
|
||||
}
|
||||
|
||||
$user = auth()->user();
|
||||
|
||||
|
||||
$token = JWTAuth::claims([
|
||||
"role_id" => $user->role_id
|
||||
])->fromUser($user);
|
||||
@@ -65,9 +66,9 @@ class AuthController extends Controller
|
||||
"token_type" => "Bearer",
|
||||
"expires_in" => JWTAuth::factory()->getTTL() * 60,
|
||||
"user" => [
|
||||
"id" => $user->id,
|
||||
"name" => $user->name,
|
||||
"email" => $user->email,
|
||||
"id" => $user->id,
|
||||
"name" => $user->name,
|
||||
"email" => $user->email,
|
||||
"role_id" => $user->role_id,
|
||||
"password" => $user->password,
|
||||
"created_at" => $user->created_at,
|
||||
@@ -103,14 +104,22 @@ class AuthController extends Controller
|
||||
public function me()
|
||||
{
|
||||
$user = auth()->user();
|
||||
$videosWatched = Video::select('id')
|
||||
->with('views')
|
||||
->whereHas('views', function ($q) use ($user) {
|
||||
$q->where('user_id', $user->id);
|
||||
})->count();
|
||||
$videosCount = Video::select('id')->where('is_active', true)->count();
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Utilizador obtido com sucesso',
|
||||
'data' => [
|
||||
'id' => $user->id,
|
||||
'role_id' => $user->role_id,
|
||||
'videosWatched' => $videosWatched,
|
||||
'videosCount' => $videosCount,
|
||||
],
|
||||
'errors' => null,
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user