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

Adding APP_UNINSTALLED webhook #19

Merged
merged 1 commit into from
May 17, 2021
Merged

Adding APP_UNINSTALLED webhook #19

merged 1 commit into from
May 17, 2021

Conversation

paulomarg
Copy link
Collaborator

WHY are these changes introduced?

Now that we have OAuth working, we can add a webhook handler for the APP_UNINSTALLED event, which will delete all of a shop's sessions in the database to make sure that shop goes through OAuth again if it ever reinstalls the app.

WHAT is this pull request doing?

Using the library to handle the uninstallation webhook, and wiping all sessions for the shop when that happens, to ensure it is not considered installed in the future.

Type of change

  • Patch: Bug (non-breaking change which fixes an issue)
  • Minor: New feature (non-breaking change which adds functionality)
  • Major: Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • I have added a changelog entry, prefixed by the type of change noted above
  • I have added/updated tests for this change

@paulomarg paulomarg requested a review from a team as a code owner May 17, 2021 18:28
Copy link
Contributor

@MuhammadFarag MuhammadFarag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work 👏

Comment on lines +93 to +106
$response = Registry::register(
path: '/webhooks',
topic: Topics::APP_UNINSTALLED,
shop: $shop,
accessToken: $session->getAccessToken(),
);
if ($response->isSuccess()) {
Log::debug("Registered APP_UNINSTALLED webhook for shop $shop");
} else {
Log::error(
"Failed to register APP_UNINSTALLED webhook for shop $shop with response body: " .
print_r($response->getBody(), true)
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can think of a way to pull this code into the library. Webhooks path could be a configuration. We already know the topics from the Registery::addHandler. Not part of this PR though

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mean, we don't need to explicitly pass arguments to register. Maybe we can have a method registerAll that would register all webhooks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, interesting, that's a really good idea. I just wonder if it wouldn't 'hide' the topics a little bit (and not sure if that's even a problem). We could also just make that an app method, though it's probably generic enough that it can go into the lib.

Base automatically changed from add-oauth-begin to main May 17, 2021 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants