Open dlatikaynen opened 4 months ago
Experiencing the same issue here.
0 flutter_web_auth_2 0x0000000102cfd6bc Swift runtime failure: Unexpectedly found nil while unwrapping an Optional value + 0 (SwiftFlutterWebAuth2Plugin.swift:0)
1 flutter_web_auth_2 0x0000000102cfd6bc closure #1 in SwiftFlutterWebAuth2Plugin.handle(_:result:) + 1312 (SwiftFlutterWebAuth2Plugin.swift:29)
2 flutter_web_auth_2 0x0000000102cfdb64 thunk for @escaping @callee_guaranteed (@in_guaranteed URL?, @guaranteed Error?) -> () + 192 (<compiler-generated>:0)
3 AuthenticationServices 0x00000002065cbb70 -[ASWebAuthenticationSession _cancelWithError:] + 40 (ASWebAuthenticationSessionIOS.m:312)
4 AuthenticationServices 0x00000002065cb9f4 -[ASWebAuthenticationSession _startDryRun:] + 644 (ASWebAuthenticationSessionIOS.m:228)
5 flutter_web_auth_2 0x0000000102cff0e8 specialized SwiftFlutterWebAuth2Plugin.handle(_:result:) + 2904 (SwiftFlutterWebAuth2Plugin.swift:100)
6 flutter_web_auth_2 0x0000000102cfd714 specialized SwiftFlutterWebAuth2Plugin.handle(_:result:) + 16 (<compiler-generated>:0)
7 flutter_web_auth_2 0x0000000102cfd714 @objc SwiftFlutterWebAuth2Plugin.handle(_:result:) + 84
8 Flutter 0x00000001037c9a38 0x1031e8000 + 6167096
9 Flutter 0x000000010322bc00 0x1031e8000 + 277504
We partially worked around the crash by adding a login button instead of automatically logging in on startup, but it still crashes occasionally.
I am seeing this issue on app startup too.
The code that is generated for SwiftFlutterWebAuth2Plugin specifies a completionHandler that assumes a session exists. It crashes on this line:
(sessionToKeepAlive as! ASWebAuthenticationSession).cancel()
The problem is that a prior session was NOT established yet. The completionHandler is being called with an error related to app window management:
Error Domain=com.apple.AuthenticationServices.WebAuthenticationSession Code=3 "The UIWindowScene for the returned window was not in the foreground active state." UserInfo={NSDebugDescription=The UIWindowScene for the returned window was not in the foreground active state.}
A fix that works for me is to determine when the app actually reports that it is in foreground, and only attempt a network operation at that point. I used a solution that is specified here: https://stackoverflow.com/questions/51835039/how-do-i-check-if-the-flutter-application-is-in-the-foreground-or-not
Works perfectly well on Android.
crashlog.txt
oauth2_client: ^3.2.2
Since this is some kind of null reference exception (or "unpacking-asserted-not-null value which is actually null") kind of error, maybe there is now a version mismatch between this and the underlying plugin, and we feed it something which is not a mandatory input in oauth2_client but (now) is in one of the underlying functions?