Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StreamSubscriptions triggering all events on auth token refresh #88

Open
marcusrohden opened this issue Nov 9, 2022 · 5 comments
Open
Assignees
Labels
bug Something isn't working maintenance Related to the maintenance of the packages/repo

Comments

@marcusrohden
Copy link

marcusrohden commented Nov 9, 2022

Hey guys,

I observed that when the service token changes (NHostClient addTokenChangedCallback is triggered), all my subscription streams attached to Hasura produce the same data again since the app started listening to them.

Is that the expected behaviour?

Would be a security breach to not refresh the token every minute but once every couple of hours as a way around? What's the drawback?

Any suggestions?

Currenly utilising nhost_sdk: ^3.0.4 and nhost_graphql_adapter: ^2.0.3

Thank you

@MaxSchilling
Copy link

Facing the same issue and thinking about ways to fix it... Currently it produces major problems. One solution could be to to work around streams and move from subscriptions to queries.. But thats a big pain..
Increasing the jwt token duration is a security no go for us. May be increased to 1,2,3 minutes, but not more and that won't help.

I am not expert enough to fully figure out if the sdk could be improved to prevent this - so if there is any help by the nhost team / SDK maintainer, that would be highly highly appreciated and also supported from our end where we can. Can't go live with the current solution..

@marcusrohden
Copy link
Author

Hi guys, any updates on this issue?

Thank you

@mhadaily mhadaily self-assigned this Dec 4, 2022
@mhadaily mhadaily added bug Something isn't working maintenance Related to the maintenance of the packages/repo labels Dec 4, 2022
@mhadaily
Copy link
Contributor

Hi,

As of now, this is pretty much expected as the new token is issued, and the connection must be reestablished with a new token. However, I am working on a new release to provide a few solutions. Please stay tuned, I will let you know once it's ready. Meanwhile, you can try the latest dev version https://pub.dev/packages/nhost_sdk/versions#prerelease

@marcusrohden
Copy link
Author

Hi @mhadaily, do you have any updates regarding this issue?

Thank you

@mhadaily
Copy link
Contributor

mhadaily commented Jan 11, 2023

Hi,
The reconnection is expected as the token is refreshing. However, there was a bug that the token was refreshed every 30 seconds, whereas the actual time was 15 minutes. This bug is fixed in the latest version now nhost_sdk: ^4.0.0-dev.8

You can upgrade to this version; however, consider that you need to remove backendUrl and instead use subdomain and region.

@marcusrohden and @MaxSchilling let me know if that works ok now for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working maintenance Related to the maintenance of the packages/repo
Projects
None yet
Development

No branches or pull requests

3 participants