gnikyt / laravel-shopify

A full-featured Laravel package for aiding in Shopify App development
MIT License
1.24k stars 374 forks source link

Alpine.js/Livewire and Power-Grid Authentication redirect hangup #1245

Closed unplugged216 closed 1 year ago

unplugged216 commented 1 year ago

For bug reporting only! If you're posting a feature request or discussion, please ignore.

Expected Behavior

When making a a request via Livewire, after adding the auth header, we expect the requested resource to load.

Current Behavior

When queries are fired, the appropriate header is added. However, the middleware "verify.shopify" is forcing a redirect through responding with HTML and trying to redirect from javascript. This cause the request to end and errors abound.

This does not work...

Steps to Reproduce

  1. Use livewire
unplugged216 commented 1 year ago

I believe I solved my own problem.... Yay! I added the following to token_handler.blade.php

        if (window.Livewire) {
            // livewire
            window.livewire.addHeaders({
                'Authorization': bearer,
                'content-type': 'application/json',
                'X-Requested-With': 'XMLHttpRequest'
            });
        }

Since this package doesn't recognize Liveware, which is identified in the request, we need to add a little finesse to it. This should work for anyone using livewire combined with this package.