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

REST API endpoint /users changes do not get reflected to the client app #1939

Open
oyalhi opened this issue Mar 30, 2024 · 6 comments
Open
Labels
cloud Dexie Cloud issue

Comments

@oyalhi
Copy link

oyalhi commented Mar 30, 2024

We have a stripe webhook on our server, when a customer purchases a subscription, the hook gets triggered.

After validations, we get the dexie user, change it's type to prod or eval depending on if they've subscribed or unsubscribed. This operation is successful on the server side.

However, we cannot observe the user type being updated in our client app. Even after refreshes customer still shows as eval. Only after log off and log back in does the user correctly reflect the change.

Is this a known bug? Or are there alternative ways to change user's type in a way that will be reflected on the client side (almost) immediately?

@dfahlander
Copy link
Collaborator

Yes, I am aware of this. The reason is that the prod/eval property comes from the JWT and old eval token is still valid so it's not forcibly refreshed unless eval was expired. We probably need a method in db.cloud to forcibly refresh the token. Before this is in place, one workaround is to do the following:

db.$logins.toCollection().modify({accessTokenExpiration: 1});

This will make dexie-cloud believe it needs to refresh its token.

@oyalhi
Copy link
Author

oyalhi commented Mar 31, 2024

Calling the above seems to work; however, works only on the device that we called it from. On user's other devices token is still not refreshed. Is there a workaround that we can call from the server side to force refresh tokens in all devices that user has logged in?

Also, I've tried delaying the call above to avoid errors; however, I still get these, 1 warning & 1 error:

ScreenShot 2024-03-31 at 15 26 22@2x

@dfahlander dfahlander added the cloud Dexie Cloud issue label Apr 1, 2024
@dfahlander
Copy link
Collaborator

dfahlander commented Apr 10, 2024

The cloud service (staging) is now updated to push out any updates of the user license status so that all connected clients get it reflected immediately. However, if a user's license has expired, it will not keep an open connection to the cloud anymore and the only way to refresh the status of the user is by calling db.cloud.sync().

The workaround I proposed earlier should not be used since it is not needed anymore.

Please help me verify this, and I can push the update out to production. To check if your cloud database is on staging (and has the update), browse to <your DB URL>/version. It should be 1.5.0 or higher.

@oyalhi
Copy link
Author

oyalhi commented Apr 10, 2024

Thank you David, this was the last missing piece for me and works like a charm. Below is a short demo using Stripe, albeit low quality due to size limitations. I no longer observe any errors in the console logs during the operation.

I call db.cloud.sync(); regardless if it's an upgrade or downgrade, I hope that's ok.

Database version shows as 1.4.14 but still works as expected.

ScreenShot.2024-04-10.at.08.30.14-converted.mp4

ScreenShot 2024-04-10 at 08 18 34@2x

@bennieforss
Copy link

@oyalhi Looking really good. Dexie Cloud has become really powerful with these new updates.

@naton
Copy link
Contributor

naton commented Apr 12, 2024

Looks very good indeed. Anyone building something similar for Paypal subscriptions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cloud Dexie Cloud issue
Projects
Status: Backlog
Development

No branches or pull requests

4 participants