Skip to content

Commit

Permalink
Add some defensive checks to the token blade file
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyon147 committed Nov 12, 2024
1 parent 91e505c commit e1bf25c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/resources/views/auth/token.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,20 @@
@section('scripts')
@parent
<script>
// If no host is found, we need to throw an error
const host = new URLSearchParams(location.search).get("host");
if (!host) {
throw new Error('No host found in the URL');
}
// If shopify is not defined, then we are not in a Shopify context redirect to the homepage as it
if (typeof shopify === 'undefined') {
open("{{ route('home') }}", "_self");
}
shopify.idToken().then((token) => {
const host = new URLSearchParams(location.search).get("host");
let url = new URL(`{!! $target !!}`, window.location.origin);
let url = new URL(`{!! $target !!}`, window.location.origin);
// Enforce HTTPS if the current page is using HTTPS
if (window.location.protocol === 'https:') {
url.protocol = 'https:';
Expand Down

0 comments on commit e1bf25c

Please sign in to comment.