cuongdevjs / reactjs-social-login

Group Hook ReactJS components for login social network
https://react-social-login.netlify.app
MIT License
168 stars 75 forks source link

In Microsoft Login, handlePostMessage was not being called properly due to eager removal of event. Thus, this caused a bug where you had to login a second time on the microsoft login for it to register on the app #163

Open madhav-inspexion opened 8 months ago

madhav-inspexion commented 8 months ago

As you can see on this line, the removal is called immediately when the onChangeLocalStorage is called. It does not verify first if there is an actual code or not. https://github.com/cuongdevjs/reactjs-social-login/blob/24b29fe5cda1316eb176ad14711cc3dc84edad5d/src/LoginSocialMicrosoft/index.tsx#L140C30-L140C30

By simply moving this line to after the If condition, i.e. Line 143, the issue is resolved. Here is the result:

  const onChangeLocalStorage = useCallback(() => {
    const code = localStorage.getItem('microsoft')
    if (code) {
      window.removeEventListener('storage', onChangeLocalStorage, false)
      void handlePostMessage({
        provider: 'microsoft',
        type: 'code',
        code,
      }).then(() => {
        localStorage.removeItem('microsoft')
      })
    }
  }, [handlePostMessage])
cuongdevjs commented 8 months ago

Thank you very much. But I would appreciate it if you could create a PR?

madhav-inspexion commented 8 months ago

Thanks for your response. PR has been created.

bhavesh2510 commented 4 months ago

@cuongdevjs any update on this? facing same issue just FYI, the above solution is not working