When using the msal library one can authenticate using the redirect flow. This means the user is navigated to the Microsoft sign in page and after successful authentication he is navigated back to the SPA. The following code handles this:
auth
.handleRedirectPromise()
.then(() => {
const { setAccountID } = useAccount()
setAccountID()
})
.catch((error) => {
console.log('login with redirect failed: ', error)
})
The msal method handleRedirectPromise returns a Promise which we use to set the logged on account once it's resolved. However, it would be great if it was possible to set the state of a loading button to true before this Promise gets called.
Is there a way to "hook in" to the Promise so some code can be executed before it is called?
In pseudo terms it would be something like: If handleRedirectPromise is called set the button sate loading to true and once it's resolved set it to false.