Recently, I was dealing with the fact that a user turned off my Shopify application and immediately installed it again. This caused a problem because I keep all my users in a DB table.
Login / installation works as follows:
- The user tells me his store address
- I am forwarding the user example.myshopify.com/admin/oauth/authorize where access is granted. to my application
- I check if this store URL is stored in my local user database
- If not: I request a permanent access token and forward the user to the plan selection page
- If yes: I get the saved access token from the user database and register the user in my application.
Removal:
- User uninstalls my app in his Shopify backend
- Shopify sends a webhook to my application.
- I delete user data from the user database
The problem is that webhooks are sometimes delayed. If the user uninstalls and instantly reinstalls, my application will consider that the installation is an attempt to enter the system and will now use the invalid access token stored in the user database.
I decided that I could just check if the redirect from the authorization page contains a temporary access token, and if so, it will be a new installation, but it seems that the access token is returned even if the application is already installed.
So my question is: how can I handle instant reinstallation gracefully? Surely there is something that I donβt notice, cannot there be such a huge "logical error" in the Shopify API?
shopify
Louis B.
source share