Invalid Client or invalid client credentials [closed]

{
  "error": "invalid_client",
  "error_description": "Invalid client or Invalid client credentials"
}

I have put everything correct for the basic authorization but still facing the same error

I have put everything correct for the basic authorization but still facing the same error. I m looking for the alternative solution or proper solutions. I m using LULU api for this.

e.nativeEvent.offsetX is 0 on mouseMove inside setState function

I have the following code that gets the cursor position on a canvas element. The code works fine in Chrome, but in Firefox, the e.nativeEvent.offsetX is 0 inside the set state function and outside is normal.

I know that the solution would be to store the offsets and then use them, but I’m curious if this is a bug or why it is not “supposed” to work.

Thank you

import React, { useEffect, useRef, useState } from "react";

const DataFirefoxNotWorking = () => {
  const [properties, setProperties] = useState(() => ({
    key1: 0,
    key2: 0,
    key4: 0,
    key3: 0,
    coordinates: { x: null, y: null },
  }));
  const canvasRef = useRef();
  const mouseMove = (e) => {
    console.log({ x: e.nativeEvent.offsetX, y: e.nativeEvent.offsetY }); // This are shown correctly
    setProperties((oldProperties) => ({
      ...oldProperties,
      coordinates: { x: e.nativeEvent.offsetX, y: e.nativeEvent.offsetY },
      // In Firefox this two are 0
      // In Chrome works
    }));
  };

  useEffect(() => {
    const canvas = canvasRef.current;
    const ctx = canvas.getContext("2d");
    canvas.width = 300;
    canvas.height = 500;
    ctx.font = "50px Arial";
    ctx.strokeText(`x: ${properties.coordinates.x}`, 10, 50);
    ctx.strokeText(`y: ${properties.coordinates.y}`, 10, 100);
  }, [properties.coordinates]);

  return (
    <div>
      <canvas
        style={{ position: "relative" }}
        ref={canvasRef}
        onMouseMove={mouseMove}
      />
    </div>
  );
};

export default DataFirefoxNotWorking;

WKWebView accessibility tree not updated after DOM change

I have a simple UIKit app that pushes a view containing a WKWebView. If VoiceOver is enabled, when the view is pushed the OS sets the accessibility focus in the back button of the navigation bar. The problem is that when this occurs, the webview is not rendered (it shows an ampty view) so I suppose the accessibility tree is created and it only contains the back button. After a while, the web DOM changes (via JavaScript) showing web content in the webview, but when trying to move the focus by swipping right, the focus doesn’t moves, it remains “stuck” into the back button (I suppose that it’s because it doesn’t know more elements in the accessibility tree)

It seems that when webview DOM is changed WKWebView doesn’t update the accessibility tree.

Is there any way to enable that a DOM change forces OS to recreate the accessibility tree?

Zod allow all keys matching regex

I’m using zod to validate some data, and I want to allow certain attributes, as well as any attribute with key matching /metadata_hash_.*/.

Say for example this schema:

import { z } from "zod";

const schema = z.object({
  a: z.number(),
  b: z.number()
});

Now I want to allow any attribute matching /metadata_hash_.*/. I’ve tried:

  • Merging with a record object, but that was not allowed
  • using .catchall, but I did not find a way to check the key, only the value
  • using z.preprocess and converting the keys into an object and validating that as a z.record(z.string().refine(...), z.string()),
    but this changes the shape of the object which I don’t really want.

Is there a good way to do this?

How to debug scroll event fired a lot later than the pointermove event?

With Chrome’s 20x slowdown + device emulation, you can see that the first scroll event occurs 230ms after the first mousemove event:

enter image description here

On Android (a flagship 2023 phone), without any artificial slowdown, there’s also noticeable lag when scrolling. I tried all the common fixes:

  • GPU acceleration with translateZ(0)
  • passive: true on scroll handlers
  • React time slicing
  • disabling packages one-by-one
  • avoid layout/paint

Since the web app is too complicated to make an MRE, this question isn’t about solving my specific problem. Instead, I’m looking for general ways to debug scroll lag issues. E.g.:

  • how to tell if a specific CSS property is expensive
  • how to figure out why “Hit Test” is taking so long
  • resources to understand why multiple pointermove events occur before the first scroll event

In addition to the common fixes I’ve listed, what are some other steps to debug this type of issue?

How can I use concat to convert a dom NodeList to a array?

I found the statement [].concat(anotherArray) is not completely same to the [...anotherArray].Especially when we use it to convert NodeList.

I want to iterate a NodeList in Vue template, like this:

<div>{{ [...theUl.children].map(li => li.innerText) }}</div>

There is a problem: Vue converts [...theUl.children] to [].concat(theUl.children) and execute it, you can try it yourself, the result is weird and different to [...theUl.children]: you will get a array like [[li, li, li]].
I don’t konw what happened.Who can explain this?
Thank you!

Why res.clearCookie() is not working after deploying to vercel?

First of all, everything works fine when running on localhost.

However, after deploying the app to Vercel when the user tries to log out it should clear cookies with res.clearCookie() but it doesn’t and when the page is refreshed the user remains logged in.

Also, after deploying the app to Vercel the new token is generating fine but is not being stored in the browser’s cookies.

here is the function to LogOut

async function userLogout(req,res){
try {
        const tokenOption = {
            httpOnly : true,
            secure : true,
            sameSite : 'None'
        }

        res.clearCookie("token",tokenOption)
        res.clearCookie("refresh_token",tokenOption)

        res.json({
            message: "Logged out successfully",
            error : false,
            success : true,
            data : []

        })
    }catch(err){
    res.json({
        message : err.message || err  ,
        error : true,
        success : false,
      })
     }
    }

module.exports = userLogout

I tried to debug but it was no luck as my localhost was running everything perfectly

Why “Favor composition over inheritance” and not “Favor aggreggation over inheritance”?

I have read many different articles on “Favor composition over inheritance” over the years and despite reading so many, actually finding clear concise code examples has been difficult.

I understand that all examples will generally be overly simplified, but here are the most common code examples I see across different articles along with my current understanding;

class Animal {
  eat() {...}
  sleep() {...}
}

class Doggo extends Animal { ... }

console.log((new Doggo()).eat())

With inheritance, if we modify the Parent class (Animal), we may subtly affect sub-classes in different ways; Parent methods change which impact the sub-class or many superfluous methods are added to the Parent that the sub-class doesn’t need or the likelihood of mutation is increased from Parent class properties etc.

In time the Parent class becomes bloated or an incorrect abstraction so we need to keep separating the Parent into more sub-classes and inherit from those (i.e. Animal – Dog – Doggo) which incurs it’s own cost.

class Doggo {
  constructor() {
    this.eat = (new Eat()).eat;
    this.sleep = (new Sleep()).sleep;
  }
}

console.log((new Doggo()).eat())

An alternative is composition.

The difference, is that composition involves the class being -composed- of other objects. The benefit being the Doggo class only uses the objects (functions) it really needs.

From my understanding of composition, when the Doggo object is destroyed, the objects it is comprised of (Eat, Sleep) are also destroyed.

I have seen many examples where these objects are instantiated in the class’ constructor, just like above. Maybe I was unlucky to find such examples, but I think you can see where I am going with this;

class Doggo {
  constructor(eat, sleep) {
    this.eat = eat.eat;
    this.sleep = sleep.sleep;
  }
}

let eat = new Eat()
let sleep = new Sleep()
console.log((new Doggo(eat, sleep)).eat())

Analogous to composition, is -aggregation-, where a classes dependencies exist independent of the class. Most often I see this represented as the dependencies being injected (Dependency Injection). In this case, when the Doggo class is destroyed, the Eat and Sleep classes continue to exist (if called again after the Doggo class clean-up).

Now, from a testing point of view, to me, aggregation is clearly the better choice when feasible, since mock dependencies can be injected during testing, while with aggregation, those dependencies are difficult/impossible to mock.

So if my simplified examples are correct, as an alternative to inheritance, why would composition be preferred over aggregation? Or are my examples too simplified and focusing on the wrong take-away?

As an aside, I have also seen examples suggest that “composition over inheritance” is actually about defining many discrete interfaces and having a class implement those instead. I believe there is overlap if you combine the interfaces along with the use of dependency objects, but the use of interfaces alone is more in line with the SOLID Interface Segregation Principle. Would this also be correct to state?

How Can QbitSuite by QuantmHill Solve My Business Management Challenges?

  1. Difficulty in simplifying accounting and billing processes.
  2. Challenges in managing HR tasks efficiently in one place.
  3. Trouble keeping projects on track and ensuring business growth.
  4. Struggles with managing leads effectively and improving conversion rates.
  5. Complications in maintaining detailed customer and vendor records.

I tried using various software solutions for different aspects of business management, but they often lacked integration and user-friendliness. I was expecting an all-in-one platform that could handle accounting, HRM, project management, lead tracking, and customer/vendor details seamlessly. I wanted a solution that would streamline operations and boost efficiency without switching between multiple tools.

Change the title and URL on the main page when clicking on a link in the iframe

I need your help, I have a parent A page with an integrated B iframe.

When I click on a link in the B iframe, I want to retrieve the title and url of the clicked link and pass it to the main page to simulate navigation.

It’s essential that the page doesn’t reload.

To do this, I use the javascript message API and the history API.
This works fine, but my history doesn’t work properly anymore, as I have to click twice on previous for it to work.

Or I can’t get the corresponding url in the url bar.

I know that what I’m trying to do is rather complicated, but if anyone has a solution or a clue, I’d love to hear from you.

Thanks in advance

Main page :

  <iframe id="childFrame1" name="childFrame1" src="child1.html" width="600" height="400"></iframe>

    <script>
        // Ajoute un gestionnaire pour l'événement popstate dans le parent
        window.addEventListener('popstate', function(event) {
            alert('pop')
            console.log(event.state)

              if (event.state && event.state.url) {
                const iframe = document.querySelector("#childFrame1");
                iframe.src = event.state.url;
            }
        });

        // Écoute les messages provenant des iframes
        window.addEventListener('message', function(event) {
            if (event.data.type === 'updateUrl') {
                // Met à jour l'URL et le titre sans ajouter une nouvelle entrée à l'historique
                history.pushState({ url: event.data.url, title: event.data.title, source: event.data.source }, event.data.title, event.data.url);

                document.title = event.data.title;
            }
        });


    </script>

Iframe code:

<a href="/page1" data-title="Page 1">Link to Page 1</a>
    <a href="/page2" data-title="Page 2">Link to Page 2</a>

    <script>

      function navigate(url, title) {
        window.parent.postMessage(
          {
            type: "updateUrl",
            url: url,
            title: title,
            source: "iframe"
          },
          "*"
        );
      }

      // Gestion des boutons
      document.getElementById("navigate1").addEventListener("click", function () {
        navigate("/page1", "Page 1");
      });

      document.getElementById("navigate2").addEventListener("click", function () {
        navigate("/page2", "Page 2");
      });

      // Gestion des liens
      document.querySelectorAll('a').forEach(function(link) {
        link.addEventListener('click', function(event) {
          event.preventDefault(); // Empêche le comportement par défaut
          navigate(link.getAttribute('href'), link.getAttribute('data-title'));
 location.assign(link.href);
        });
      });
    </script>

From what I’ve read, the only way to change the url is to use pushState, which is a problem in my case.

Parse aggregate pipeline to match objects with a valid pointer field

const query = new Parse.Query("TimeSpent");
const pipeline = [
    {
        $match: {
            date: {
                $gte: new Date(startDate),
                $lte: new Date(endDate)
            },
            parent: { $exists: true }
        }
    },        
    {
        $group: {
            _id: '$staff',
            minutes: { $sum: "$minutes" }
        }
    }
];    

try {        
    const results = await query.aggregate(pipeline);      
    return results;
} catch (error) {
    console.error('Error while aggregating:', error);
}

I have a parse pipeline code that aggregates the time spent per staff based on a Class “TimeSpent”. This class has “parent” field which is a Pointer that points to some sort of parent.

In the $match phase, I want to ignore the objects if they do not have a parent field, or for some reason the parent object is deleted, or non-existent.

Currenltly by setting parent: { $exists: true } it doesn’t know if the parent pointer is pointing to something or not.

How to improve this code?

How can I store the response of my axios get request as json in node.js?

I’m trying to send a request to an api using axios and store the json response in a variable. When I output the response to the console, it shows it, but when setting a variable equal to it and returning said variable, I only get Promise { } as an output.

const { default: axios } = require("axios");

async function getAvgPrice() {
    var data = []; // or whatever we would have to declare for a json object
    await axios.get("https://api.com/example.json")
    .then(function(res) {
        console.log(res); // <-- This outputs the correct response to console
        data.push(res);   // <-- This just doesn't do anything
    });
    return data;
}

var x = getAvgPrice();
console.log(x); // <-- (Output: Promise { <pending> })

I tried to send a request to an api and store the response as json and am only able to return a promise.

AMR audio type file is not playing [duplicate]

<audio controls>

Your browser does not support the audio element.

I have tested it from the local amr audio file with proper src location loaded in browser but when i hit play button sound is not playing for amr type alone. Anyone have solution for this?

I checked in w3schools also, other audio types are played only amr is not played i don’t have whether amr is not supported by default

Prevent VS Code suggesting turning a function into a class

I have an issue with VS Code suggestion turning a function in JS into a class. It gives the following suggestion message:

This constructor function may be converted to a class declaration. ts(80002)

image of the error message and syntax highlighting as shown in visual studio code

I do understand why the suggestion and highlighting are done as described in this SO question.

While it is just a suggestion it does not alter the code but the wrongly highlighted function annoys me. I have found a SO question on how to disable all suggestions.

I still want to know if there is an option to disable only this specific suggestion and the wrong highlighting instead of all.

How can only this specific highlighting fixed to show the color of functions instead of classes?

(Code for those that require all questions to have code in the question itself):

function init() {
  BUTTON_LABELS.forEach((label, index) => {
    const BUTTON = document.createElement('button');
    BUTTON.addEventListener('click', move);
    BUTTON.ariaLabel = label;
    BUTTON.dataset.id = index;
    BOARD.appendChild(BUTTON);
  })
}

function move() {
  if (!this.textContent.length) {
    this.textContent = PLAYERS[turn];
    saveMove(this.dataset.id);
  }
}