Code Monkey home page Code Monkey logo

Comments (3)

Spiral-Memory avatar Spiral-Memory commented on September 25, 2024

@abhinavkrin, I believe the issue lies in the execution order of the getChannelInfo or getCurrentUser function with respect to whether the currentUser or currentUser.authToken has been set. Upon refreshing, before currentUser is set, it sends a request to the backend to obtain the userId and authToken using const { userId, authToken } = await this.auth.getCurrentUser() || {};. The function runs before the currentUser or currentUser.authToken is set, causing both variables to return undefined. Consequently, it sends a request to the Rocket Chat REST API with undefined information, leading to the inability to fetch the required data upon refresh. I would like to address this issue, but I am unsure how to fix the order of execution. Could you please guide me on this so that I can begin working on it?

I have debugged the issue, and here are my findings:

Console logs on refresh:

image

In RocketChatAuth.ts, I used the getCurrentUser() function to debug the issue:

image

from embeddedchat.

Spiral-Memory avatar Spiral-Memory commented on September 25, 2024

After debugging, I found that in the EmbeddedChat.js frontend file, the isUserAuthenticated variable was being set to true before successfully connecting to the RCInstance. This premature setting caused a state change, triggering the execution of the useEffect hook which runs getChannelInfo() function in ChatHeader.js. Since this function requires user information to fetch data which is not available as of now, it sent undefined credentials to the REST API backend, resulting in an error response and the inability to retrieve channel information.

To fix this, I modified the code so that isUserAuthenticated changes to true only after a successful connection is established. This ensures that this.currentUser is properly set on the backend, allowing for correct functionality upon refresh. I've submitted a pull request for your review, checking if my changes are correct.

from embeddedchat.

abhinavkrin avatar abhinavkrin commented on September 25, 2024

Thanks @Spiral-Memory for the investigation. 💯

from embeddedchat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.