One solution to this issue is to use a native mobile app instead of a web app. Native apps can use features like background processing to continue running tasks even when the app is not in the foreground.
If using a web app is a requirement, you may need to redesign your app to work within the limitations of iOS background execution. For example, you could save the authentication code to local storage and resume the authentication process when the user returns to the app. You could also use push notifications or other background features to update the user when the authentication process is complete.
Overall, it's important to design your app with the limitations of the platform in mind to ensure a seamless user experience.