Skip to content

Commit

Permalink
Add webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
allenchazhoor committed Dec 17, 2024
1 parent 9ab71bf commit bdfe4af
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@

## 2024.12.04

- [875](https://github.com/Shopify/shopify-app-template-remix/pull/875) Add Scopes Update Webhook

## 2024.12.04

- [#891](https://github.com/Shopify/shopify-app-template-remix/pull/891) Enable remix future flags.

## 2024.11.26

- [888](https://github.com/Shopify/shopify-app-template-remix/pull/888) Update restResources version to 2024-10

## 2024.11.06
Expand All @@ -33,7 +36,7 @@

## 2024.09.17

- [842](https://github.com/Shopify/shopify-app-template-remix/pull/842)Move webhook processing to individual routes
- [842](https://github.com/Shopify/shopify-app-template-remix/pull/842) Move webhook processing to individual routes

## 2024.08.19

Expand Down
21 changes: 21 additions & 0 deletions app/routes/webhooks.app.scopes_update.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { ActionFunctionArgs } from "@remix-run/node";
import { authenticate } from "../shopify.server";
import db from "../db.server";

export const action = async ({ request }: ActionFunctionArgs) => {
const { payload, session, topic, shop } = await authenticate.webhook(request);
console.log(`Received ${topic} webhook for ${shop}`);

const current = payload.current as string[];
if (session) {
await db.session.update({
where: {
id: session.id
},
data: {
scope: current.toString(),
},
});
}
return new Response();
};
5 changes: 5 additions & 0 deletions shopify.app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ api_version = "2024-10"
uri = "/webhooks/app/uninstalled"
topics = ["app/uninstalled"]

# Handled by: /app/routes/webhooks.app.scopes_update.tsx
[[webhooks.subscriptions]]
topics = [ "app/scopes_update" ]
uri = "/webhooks/app/scopes_update"

# Webhooks can have filters
# Only receive webhooks for product updates with a product price >= 10.00
# See: https://shopify.dev/docs/apps/build/webhooks/customize/filters
Expand Down

0 comments on commit bdfe4af

Please sign in to comment.