all(), [ 'email' => 'required|email', 'password' => 'required', ]); if ($validator->fails()) { $validationErrors = $validator->errors()->all(); Log::error("Login validation error: " . implode(", ", $validationErrors)); return jsonResponseWithErrorMessageApi($validationErrors, 403); } $isExistEmail = User::where('email', $request->email)->first(); if ($isExistEmail == null) { return jsonResponseWithErrorMessageApi(__('auth.incorrect_email'), 403); } if ($isExistEmail && !(Hash::check($request->password, $isExistEmail->password))) { Log::error('Entered Password is wrong for ' . $request->email); return jsonResponseWithErrorMessageApi(__('auth.incorrect_password'), 403); } $credentials = [ 'email' => $request->email, 'password' => $request->password, ]; if (Auth::attempt($credentials)) { $user = Auth::user(); $token = JWTAuth::fromUser($user); // Return success response with JWT token $response = [ 'access_token' => $token, 'user' => $user, ]; return jsonResponseWithSuccessMessage(__('auth.data_fetched_successfully'), $response, 200); } } catch (QueryException $e) { Log::error('Customer Login Failed: ' . $e->getMessage()); return jsonResponseWithErrorMessageApi(__('auth.authentication_failed'), 401); } } }