ThexXTURBOXx / flutter_web_auth_2

Flutter plugin for authenticating a user with a web service
https://pub.dev/packages/flutter_web_auth_2
MIT License
51 stars 50 forks source link

How to handle redirection errors #86

Open Lilian-C opened 9 months ago

Lilian-C commented 9 months ago

Hello,

I have a question regarding the package:

For example, in the case of a server-side error during authentication, we have an error page showing up to the user (error 5XX). I would like to be able to stop the authentication process and redirect the user back to the app instead. Is there any way to catch an error during a redirection to a page (like onWebResourceError does for web views) ?

Thanks :)

ThexXTURBOXx commented 9 months ago

I think the easiest way to accomplish this is to just close the current tab (or rather simulate closing it). This will immediately show the app again on iOS and Android. In the other implementations, it won't do anything but close the app. At some point, a timeout might occurr, however.

Another possibility is to provide a callback to the app (just as if the registration was successful), but the URL query parameters contain some special string that can only occurr if the authentication was not successful - this should be done on the error page and might not be the best way to handle this, but the most fail-safe.

I don't think there is an easy way to accomplish error catching properly. But you can still try implementing it and submitting as a PR.