GitLiveApp / firebase-kotlin-sdk

A Kotlin-first SDK for Firebase
https://gitliveapp.github.io/firebase-kotlin-sdk/
Apache License 2.0
1.14k stars 155 forks source link

iOS signInWithEmailAndPassword fails to parse Firebase response when using blocking functions with Authentication #655

Open csandels opened 1 week ago

csandels commented 1 week ago

On iOS, when a Firebase blocking function attached to beforeUserSignedIn is used with Authentication and that function throws an error with a type other than "internal", the gitlive code is unable to parse the response. With other platforms, the message given to the HttpsError constructor in the function is passed all the way to the client code as the message on the exception, as expected. But with iOS, a client side error is thrown saying "JSON text did not start with array or object and option to allow fragments not set. around line 1, column 0.".

https://firebase.google.com/docs/auth/extend-with-blocking-functions?gen=2nd

When function does this: throw new HttpsError('internal', 'Problem with authentication')

Error looks like this: Error Domain=FIRAuthErrorDomain Code=17999 "An internal error has occurred, print and inspect the error details for more information." UserInfo={NSUnderlyingError=0x600000d61890 {Error Domain=FIRAuthInternalErrorDomain Code=3 "(null)" UserInfo={FIRAuthErrorUserInfoDeserializedResponseKey={ code = 503; errors = ( { domain = global; message = "Error code: 47"; reason = backendError; } ); message = "Error code: 47"; }, NSUnderlyingError=0x600000b1ddc0 {Error Domain=com.google.HTTPStatus Code=503 "(null)" UserInfo={data={length = 207, bytes = 0x7b0a2020 22198272 6f72223a 201a3a20 ... 5d0a2020 7d0a7d0a }, data_content_type=application/json; charset=UTF-8}}}}, FIRAuthErrorUserInfoNameKey=ERROR_INTERNAL_ERROR, NSLocalizedDescription=An internal error has occurred, print and inspect the error details for more information.}

When function does this: throw new HttpsError('unauthenticated', 'Some other reason')

Error looks like this: Error Domain=FIRAuthErrorDomain Code=17999 "An internal error has occurred, print and inspect the error details for more information." UserInfo={NSLocalizedDescription=An internal error has occurred, print and inspect the error details for more information., NSUnderlyingError=0x600000fee456 {Error Domain=FIRAuthInternalErrorDomain Code=2 "(null)" UserInfo={NSUnderlyingError=0x600000fee123 {Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set. around line 1, column 0." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set. around line 1, column 0., NSJSONSerializationErrorIndex=0}}}}, FIRAuthErrorUserInfoNameKey=ERROR_INTERNAL_ERROR}