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

feat: EASDK redirect fix #26

Merged
merged 1 commit into from
Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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