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
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])
Thank you very much. But I would appreciate it if you could create a PR?
Thanks for your response. PR has been created.
@cuongdevjs any update on this? facing same issue just FYI, the above solution is not working