js-sdk icon indicating copy to clipboard operation
js-sdk copied to clipboard

[Feature]: authWithOAuth2 support AbortSignal

Open shynome opened this issue 2 years ago • 5 comments

shynome avatar Dec 19 '23 07:12 shynome

Please don't open issues without description. Could you elaborate what is your use case?

ganigeorgiev avatar Dec 19 '23 07:12 ganigeorgiev

If you are trying to cancel a pending authWithOAuth2() call I guess we can introduce a requestKey support similar to the other SDK methods, which will allow cancelling with pb.cancelRequest(requestKey).

The problem with the "all-in-one" authWithOAuth2() call is that it performs 3 different requests - listAuthMethods, start a realtime subscription and finally call to the authWithOAuth2Code() method. It is doable but requires some more thinking to structure it properly.

ganigeorgiev avatar Dec 19 '23 08:12 ganigeorgiev

I have found requestKey, but I feel it is not a good interface for javascript, I like use js native cancel signal AbortSignal more

That’s a bit of a digression, now typescript support using, we can refactor cleanup code. I would love to contribute, but my code format is diffrent with you, maybe upload .editorconfig file is good idea

shynome avatar Dec 19 '23 08:12 shynome

Under the hood the builtin request cancellation is managed via AbortController instances. There are no plans for now to pass AbortController/AbortController.signal as argument because it will be inconsistent with the other APIs and the internal implementation may change in the future.

As mentioned earlier, I'll consider supporting passing requestKey to the "all-in-one" authWithOAuth2() method but I'll have to think a little more on it and for now remains a low priority.

ganigeorgiev avatar Dec 19 '23 09:12 ganigeorgiev

Thanks for your reply, I had implement it by myself, so it will not block me.

requestKey is fine, but it need export cancelRequestKey function, let user can muanal control cancel it

shynome avatar Dec 19 '23 09:12 shynome

Support for cancelling the OAuth2 flow using requestKey is added in v0.21.4 release.

ganigeorgiev avatar Jul 27 '24 09:07 ganigeorgiev