gnikyt / laravel-shopify

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

403 error when doing Axios POST request to Backend Route #1158

Closed benson336 closed 2 years ago

benson336 commented 2 years ago

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

Expected Behavior

Try to pass data to the backend by doing simple POST request, and save data into the database.

Current Behavior

When I did the POST request, I keep getting 403 error response.

Failure Information

Keep getting 403 error response from the POST request.

Steps to Reproduce

  1. Create an Axios POST request to the backend. For example the code below: async function saveData(){ await axios.post('/savedata', { headers: { Authorization: Bearer ${window.sessionToken}}, params: {info: "test"} }).then (function(response){ console.log(response); }).catch(function(error){ console.log(error); }); }

  2. In web.php, I have below route to handle the POST request: Route::post('/savedata', 'MainController@store')->middleware(['verify.shopify']);

  3. Inside the controller, I use Accessing API for the current shop to do a test response by returning $shop variable. class MainController extends Controller{ public function store(Request $request) { $shop = Auth::user(); return $shop; } }

  4. I keep getting 403 errors from the frontend response.

Context

Failure Logs

Error: Request failed with status code 403 at createError (app.js:61851:15) at settle (app.js:62112:12) at XMLHttpRequest.handleLoad (app.js:61320:7)