fly-apps / fly-laravel

Run your Laravel apps on Fly
40 stars 3 forks source link

Initial Cookie Session Driver for Launching Web App #50

Closed KTanAug21 closed 1 year ago

KTanAug21 commented 1 year ago

Hi Team!

SO, earlier today, I created a simple file uploader that worked locally but not on my fly.io web app.

I. Problem:

Whenever I uploaded a file in the fly.io app, I got an error from Laravel, with the "csrf token does not match" error.


II. Break down of solution:

1. Why am I getting the token mismatch error? -There where initially 2 vms created for the web app. Since both were up, I think the session token got set in one vm, while the upload was requested to the other vm which didnt contain the session token in 1st vm.

2. I spent some time buffering on what was happening( because it locally works, I was checking if something was up with my code,etc ) -I at first didnt think there was an issue with session, but good thing I remembered the same issue being solved thanks to this. But not all incoming Laravel devs would be able to see it immediately. So they'll keep wondering why form submission is working locally but not on fly.

3. Hopefully they see https://fly.io/laravel-bytes/full-stack-laravel/ early on and immediately attach a redis app as session driver. -But, in case they don't, it would be really helpful to set up the session driver to cookie by default to avoid the csrf token issue when there is more than 1 vm running for the web app. -Once they run the redis launch and deploy, it should replace the cookie session driver with the redis driver


III. Solution:

Apply cookie session driver solution as described here! This configuration would of course be overriden once they apply redis as their session driver either manually or through the redis commands of fly-laravel