Skip to content

Commit

Permalink
Merge pull request #26 from seka19/easdk-fix
Browse files Browse the repository at this point in the history
feat: EASDK redirect fix
  • Loading branch information
seka19 authored Mar 10, 2022
2 parents 1e667ac + 8ecc1e9 commit 70644ec
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
7 changes: 6 additions & 1 deletion src/ShopifyApp/Traits/AuthControllerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ public function authenticate(AuthShop $request)

return View::make(
'shopify-app::auth.fullpage_redirect',
compact('authUrl', 'shopDomain')
[
'authUrl' => $authUrl,
'shopDomain' => $shopDomain,
'host' => $request->host ?? base64_encode($shopDomain . '/admin'),
]
// compact('authUrl', 'shopDomain')
);
}

Expand Down
25 changes: 17 additions & 8 deletions src/ShopifyApp/resources/views/auth/fullpage_redirect.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,31 @@

<title>Redirecting...</title>

<script src="https://unpkg.com/@shopify/app-bridge{{ config('shopify-app.appbridge_version') ? '@'.config('shopify-app.appbridge_version') : '' }}"></script>
{{--<script src="https://unpkg.com/@shopify/app-bridge-utils{{ config('shopify-app.appbridge_version') ? '@'.config('shopify-app.appbridge_version') : '' }}"></script>--}}

<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function () {
var redirectUrl = "{!! $authUrl !!}";
if (window.top == window.self) {
// If the current window is the 'parent', change the URL by setting location.href
window.top.location.href = redirectUrl;
} else {
// If the current window is the 'child', change the parent's URL with postMessage
normalizedLink = document.createElement('a');
normalizedLink.href = redirectUrl;
// If the current window is the 'child', change the parent's URL with postMessage
var normalizedLink = document.createElement('a');
normalizedLink.href = redirectUrl;
var AppBridge = window['app-bridge'];
var createApp = AppBridge.default;
var Redirect = AppBridge.actions.Redirect;
var app = createApp({
apiKey: '{{ config('shopify-app.api_key') }}',
//shopOrigin: "{{ $shopDomain }}",
host: "{!! $host !!}",
});
data = JSON.stringify({
message: 'Shopify.API.remoteRedirect',
data: { location: redirectUrl },
});
window.parent.postMessage(data, "https://{{ $shopDomain }}");
var redirect = Redirect.create(app);
redirect.dispatch(Redirect.Action.REMOTE, normalizedLink.href);
}
});
</script>
Expand Down
5 changes: 4 additions & 1 deletion src/ShopifyApp/resources/views/layouts/default.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@

@if(config('shopify-app.appbridge_enabled'))
<script src="https://unpkg.com/@shopify/app-bridge{{ config('shopify-app.appbridge_version') ? '@'.config('shopify-app.appbridge_version') : '' }}"></script>
{{--<script src="https://unpkg.com/@shopify/app-bridge-utils{{ config('shopify-app.appbridge_version') ? '@'.config('shopify-app.appbridge_version') : '' }}"></script>--}}

<script>
var AppBridge = window['app-bridge'];
var createApp = AppBridge.default;
var app = createApp({
apiKey: '{{ config('shopify-app.api_key') }}',
shopOrigin: '{{ ShopifyApp::shop()->shopify_domain }}',
//shopOrigin: '{{ ShopifyApp::shop()->shopify_domain }}',
host: "{{ \Request::get('host') }}",
forceRedirect: true,
});
</script>
Expand Down

0 comments on commit 70644ec

Please sign in to comment.