Skip to content

Commit

Permalink
Support App Bridge 2.0 in shopify_app
Browse files Browse the repository at this point in the history
  • Loading branch information
rezaansyed committed Apr 1, 2021
1 parent 2c608f0 commit fd775a1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
15 changes: 14 additions & 1 deletion docs/Troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* [My app is still using cookies to authenticate](#my-app-is-still-using-cookies-to-authenticate)
* [My app can't make requests to the Shopify API](#my-app-cant-make-requests-to-the-shopify-api)

[Migrating to App Bridge 2.0](#migrating-to-app-bridge-2.0)

## Generators

### The shopify_app:install generator hangs
Expand Down Expand Up @@ -138,4 +140,15 @@ _Example:_ If your embedded app cannot handle server-side XHR redirects, then co
X-Shopify-API-Request-Failure-Unauthorized: true
```

Then, use the [Shopify App Bridge Redirect](https://shopify.dev/tools/app-bridge/actions/navigation/redirect) action to redirect your app frontend to the app login URL if this header is set.
Then, use the [Shopify App Bridge Redirect](https://shopify.dev/tools/app-bridge/actions/navigation/redirect) action to redirect your app frontend to the app login URL if this header is set.

## Migrating to App Bridge 2.0

In order to upgrade your embedded app to the latest App Bridge 2.0 version, please refer to the [migration guide](https://shopify.dev/tutorials/migrate-your-app-to-app-bridge-2).

To ensure that your app's embedded layout doesn't import App Bridge 2.0 before fully migrating, make the following change to bind it to v1.x.

```diff
- <script src="https://unpkg.com/@shopify/app-bridge"></script>
+ <script src="https://unpkg.com/@shopify/app-bridge@1"></script>
```
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

// Save a session token for future requests
window.sessionToken = await new Promise((resolve) => {
app.subscribe(SessionToken.ActionType.RESPOND, (data) => {
app.subscribe(SessionToken.Action.RESPOND, (data) => {
resolve(data.sessionToken || "");
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ class HomeController < ApplicationController

def index
@shop_origin = current_shopify_domain
@host = params[:host]
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@

<%= render 'layouts/flash_messages' %>

<script src="https://unpkg.com/@shopify/app-bridge@1"></script>
<script src="https://unpkg.com/@shopify/app-bridge@2"></script>

<%= content_tag(:div, nil, id: 'shopify-app-init', data: {
api_key: ShopifyApp.configuration.api_key,
shop_origin: @shop_origin || (@current_shopify_session.domain if @current_shopify_session),
host: @host,
debug: Rails.env.development?
} ) %>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ document.addEventListener('DOMContentLoaded', () => {
var createApp = AppBridge.default;
window.app = createApp({
apiKey: data.apiKey,
shopOrigin: data.shopOrigin,
host: data.host,
});

var actions = AppBridge.actions;
Expand Down

0 comments on commit fd775a1

Please sign in to comment.