bolt-js
bolt-js copied to clipboard
How to uninstall the correct way?
Description
We have published our app in the app directory. One of the main issues we are currently dealing with is the uninstall flow of our app.
How did we set up the uninstall flow?
We first subscribed to the two events app app_uninstalled and tokens_revoked and then added event listeners to those events
and whenever the event is called we delete the user data stored on our side.
What is our issue regarding this?
Currently when someone uninstalls the app and reinstalls the app. Both on the token_revoked and app_uninstalled we would delete the app data from our side. But the issue we have repeatedly is that after reinstalling the events are getting fired after the install hook. So it throws an error.
What is our question?
What exactly should we do in these events? For now we are currently deleting the record every time a token_revoked and app_uninstalled event is being triggered, both the events we have the same logic. Please advise here.
We went through the previous issues in Github and please correct me if I am wrong, from our understanding.
token_revokedwill be fired for each token revoked.app_uninstalledwill be fired only after every token is being revoked.
What type of issue is this? (place an x in one of the [ ])
- [ ] bug
- [ ] enhancement (feature request)
- [x] question
- [ ] documentation related
- [ ] example code related
- [ ] testing related
- [ ] discussion
Requirements (place an x in each of the [ ])
- [x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
- [x] I've read and agree to the Code of Conduct.
- [x] I've searched for any related issues and avoided creating a duplicate issue.
Bug Report
Filling out the following details about bugs will help us solve your issue sooner.
Reproducible in:
@slack/bolt: 3.7.0 node version: 14.18 OS version(s): Mac OS Catalina 10.15.7
Currently when someone uninstalls the app and reinstalls the app. Both on the token_revoked and app_uninstalled we would delete the app data from our side. But the issue we have repeatedly is that after reinstalling the events are getting fired after the install hook. So it throws an error.
Can you elaborate on this? Are you saying that, when someone 'reinstalls' their app, the app installation event is being fired first before the app uninstallation and/or the token revoked event?
Do you know what the user flow for a 'reinstall' is that triggers this behaviour? Just so I can try to reproduce on my end.
@filmaj So when the user uninstalls by clicking on the "Remove app" button on the app configuration page, the following happens in sequence most of the time.
- token_revoked event is being emitted. (we delete the user data we saved)
- storeInstallation hook is being called. ( we store the data)
- fetchInstallation hook is being called. ( we return the data)
- token_revoked is being emitted( we delete again)
- app_uninstalled is being emitted ( we delete again, but it is already cleared, we have written the same logic for token_revoked and app_uninstalled)
- fetchInstallation hook is being called(we don't have the data, error is being thrown)
@RakeshRenzous so only clicking Remove App triggers all of those events? You didn't try re-installing the app?
(It's my end of day so I will check in tomorrow in my morning but just wanted to leave this question to make sure I understand 100% clearly)
@RakeshRenzous Indeed, receiving both events may look a bit redundant but the purpose of the event delivery are slightly different. In a different scenario where a user authorization is removed but the app's bot user is still alive in the workspace, your app receives only a "token_revoked" event. When all the user grants and bot user grant for the workspace are revoked, "app_uninstalled" event can be delivered too.
When it comes to the situation clicking "Remove App" button on the app config page, this operation revokes all the granted permissions for the workspace. Thus, it can trigger both "token_revoked" and "app_uninstalled". In this case, your app can handle those as below:
- "app_uninstalled": Delete all the installation data for the workspace if they still exist
- "token_revoked": Delete only the tokens for the given workspace (and user for a user token) if they still exist
I hope this helps.
@filmaj Sorry my bad I missed that, after uninstalling I immediately reinstall and you would get the above mentioned sequence of event.
@seratch Thanks for the this, yes this helps. Just to understand it even further. for the "token_revoked" we would delete the only the token data for the user ids provided in the "token_revoked" event.
👋 It looks like this issue has been open for 30 days with no activity. We'll mark this as stale for now, and wait 10 days for an update or for further comment before closing this issue out. If you think this issue needs to be prioritized, please comment to get the thread going again! Maintainers also review issues marked as stale on a regular basis and comment or adjust status if the issue needs to be reprioritized.
As this issue has been inactive for more than one month, we will be closing it. Thank you to all the participants! If you would like to raise a related issue, please create a new issue which includes your specific details and references this issue number.