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

How to uninstall the correct way?

Open RakeshRenzous opened this issue 3 years ago • 5 comments

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.

Screenshot 2022-08-21 at 12 59 21 Screenshot 2022-08-21 at 15 53 42

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.

Screenshot 2022-08-21 at 18 53 55

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_revoked will be fired for each token revoked.
  • app_uninstalled will 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

RakeshRenzous avatar Aug 21 '22 21:08 RakeshRenzous

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 avatar Aug 22 '22 17:08 filmaj

@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 avatar Aug 22 '22 23:08 RakeshRenzous

@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)

filmaj avatar Aug 23 '22 00:08 filmaj

@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.

seratch avatar Aug 23 '22 03:08 seratch

@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.

RakeshRenzous avatar Aug 23 '22 14:08 RakeshRenzous

👋 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.

github-actions[bot] avatar Sep 26 '22 00:09 github-actions[bot]

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.

github-actions[bot] avatar Oct 10 '22 00:10 github-actions[bot]