firedart icon indicating copy to clipboard operation
firedart copied to clipboard

[Web] gRPC Error (code: 14, codeName: UNAVAILABLE, message: Error connecting: Unsupported operation: SecurityContext constructor)

Open esDotDev opened this issue 4 years ago • 8 comments

Firestore seems be be throwing errors when deployed to Web.

Calling something like: Firestore.instance.collection("users").get() is triggering:

Restarted application in 201ms.
Error: gRPC Error (code: 14, codeName: UNAVAILABLE, message: Error connecting: Unsupported operation: SecurityContext constructor, details: null)
    at Object.createErrorWithStack (http://localhost:64615/dart_sdk.js:4362:12)
    at Object._rethrow (http://localhost:64615/dart_sdk.js:38245:16)
    at async._AsyncCallbackEntry.new.callback (http://localhost:64615/dart_sdk.js:38239:13)
    at Object._microtaskLoop (http://localhost:64615/dart_sdk.js:38071:13)
    at _startMicrotaskLoop (http://localhost:64615/dart_sdk.js:38077:13)
    at http://localhost:64615/dart_sdk.js:33574:9

The same code is working great on Desktop, and FirebaseAuth works on both Web/Desktop.

esDotDev avatar Nov 24 '20 08:11 esDotDev

Any thoughts on this? I can authenticate fine, but reading from firestore throws an error: image

esDotDev avatar Dec 04 '20 05:12 esDotDev

Is that still web? I have to say, I never tried running Firedart on a web browser so I'm not confident that it's actually working properly.

All tests are still passing on my end so it doesn't seem like anything broke in the meanwhile.

cachapa avatar Dec 04 '20 08:12 cachapa

Cheers, ya it's Web. I looked into it a bit more, and I guess gRPC just does not work on web, so I guess this is expected. Somehow the official firestore sdk does have a socket-like connection in browser.

I believe the "fix" would be to use this RPC channel instead of a real one, when on web: https://github.com/wav/grpc-web-dart

Little more info here: https://github.com/flutter/flutter/issues/48054

esDotDev avatar Dec 04 '20 15:12 esDotDev

If that's a drop-in fix then it should be easy to do. Would you like to try and implement it? I'd be happy to take that pull request!

cachapa avatar Dec 04 '20 17:12 cachapa

gRPC just does not work on web,

It does gRPC

image

If I understand correctly browsers does not support regular sockets, they support web-sockets that is different protocol. And for implementation I think we need to use different commands GrpcWebClientChannel from import 'package:grpc/grpc_web.dart';

guyluz11 avatar Jul 20 '21 10:07 guyluz11

Recently they added a new constructor that will handle the differences mostly: https://github.com/grpc/grpc-dart/blob/master/lib/grpc_or_grpcweb.dart. Of course this depends on the server end handling the different types of connections properly.

TimWhiting avatar Jul 20 '21 11:07 TimWhiting

Any news about this feature :) ?

ghost avatar Oct 14 '21 14:10 ghost

Another option that may help you is to switch to Appwrite instead of firebase. Didn't try it but it looks good and I think support dart on the web.

guyluz11 avatar Oct 16 '21 11:10 guyluz11

Closed by #130

cachapa avatar Feb 22 '24 12:02 cachapa