gnikyt / laravel-shopify

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

Ajax is not working. #1149

Closed hardikpanotmc closed 2 years ago

hardikpanotmc commented 2 years ago

Expected Behavior

Ajax post/get method returns a success message. POST routes send data securely. Session/Flash message or data pass and store in session or flash.

Current Behavior

Ajax returns 302 status code and error. POST routes are returning 419. if we store any data in session or flash is not get in another place of code.

khaiknievel commented 2 years ago

Most likely you have not disabled CSRF, that is why you are getting 419. https://github.com/osiset/laravel-shopify/wiki/Installation#csrf

beingak commented 2 years ago

Same issue When i has upgrade 16.0.0 to latest v(17.1.1) all Ajax request return the error [ {error: "Session token is invalid."} error: "Session token is invalid."].

@khaiknievel CSRF already disabled

khaiknievel commented 2 years ago

@beingak You might want to refer to this #895. Also the upgrading guide.

beingak commented 2 years ago

@khaiknievel I try to this axios.interceptors.request.use(function (config) { return utils.getSessionToken(window['app-bridge-app']) // requires a Shopify App Bridge instance .then((token) => { console.log('axios token'); // Append your request headers with an authenticated token config.headers.Authorization = Bearer ${token}; return config; }); });

But it not working from me I have simple AJAX request. $.ajax({ type: 'GET', dataType: 'JSON', url: ${window.location.origin}/app/fetch-messages, headers: { 'Content-Type': 'application/json', 'Accept': 'application/json', 'X-CSRF-Token': csrfToken, 'shop': 'aruntesting1.myshopify.com' }, success: (data)=> { if(data.status) $('#dashboard-fetch-message').empty().html(data.html); }, error: (xhr, textStatus, errorThrown) => console.log(xhr.statusText) });

Can you please let me know. How i can use this.

beingak commented 2 years ago

Hello, I have HTML + Laravel (Shopify app). I am doing get and post Ajax request. which has been request to web.php middleware route. it did return [ 302 ] status. [ {error: "Session token is invalid."}]

Do can you let me know how can i get the valid session token and how could be use into Ajax request.Please add example.

khaiknievel commented 2 years ago

Might be helpful #1083

Kyon147 commented 2 years ago

This sounds like an issue with your code setup, not the app so closing as a couple solutions have been provided.