reactjs-social-login icon indicating copy to clipboard operation
reactjs-social-login copied to clipboard

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

Open madhav-inspexion opened this issue 1 year ago • 3 comments

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])

madhav-inspexion avatar Jan 05 '24 16:01 madhav-inspexion

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

cuongdevjs avatar Jan 06 '24 05:01 cuongdevjs

Thanks for your response. PR has been created.

madhav-inspexion avatar Jan 06 '24 06:01 madhav-inspexion

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

bhavesh2510 avatar May 13 '24 07:05 bhavesh2510