Forem Creators and Builders 🌱

markomannux
markomannux

Posted on

InvalidAuthenticityToken with Docker setup

Hi, I'm trying to setup a development environment with Docker.
Everything is going fine but once the app is up and running, every form I try to submit receive the InvalidAuthenticityToken error.

I've searched github for existing issues and maybe is related to this. I've already commented in the issue giving some detail but maybe someone here has already encountered the issue.

Thanks!

Top comments (7)

Collapse
 
akhil profile image
Akhil Naidu

Hey @markomannux , If you have a domain, try to follow this and let me know what is the status.

This is how I eliminated most of the issues related to onboarding message errors and InvalidAuthenticityToken error

  1. I have a domain in Cloudflare, so I created a CNAME record on the subdomain(ex: dev.leewardslope.com) and attached the external IP address. Only the IP, no need of port.
  2. As the Forem service is running on the port 3000, we need to look at this issue too, so I installed Nginx and port forwarded the fort 3000 to 80. So that there is no need to use the port 3000 anymore. Here is a more detailed guide which might be useful in configuring IP: PORT to a domain name.
  3. In .env file, change the APP_DOMAIN to your domain, in my case: dev.leewardslope.com
  4. Also, don't forget to update these in GitHub too, the URL for authentication, I guess you used localhost:3000 or your IP:3000.

Also if you don't have a domain of your own and don't want to invest some bucks right now, you can use this site to create a free domain for now.

Collapse
 
markomannux profile image
markomannux

Hey @akhil , thanks for your hint: it put me on the right track. I had no clue hostname could be an issue.
Since I don't actually need social login, turns out the setup is even simpler.

I tried to set APP_DOMAIN with no luck but I noticed that container-compose.yml declared it as rails.

So I added an entry in my hosts file like this

127.0.0.1 rails
Enter fullscreen mode Exit fullscreen mode

navigated to http://rails:3000 (no need to change the port) and no more InvalidAuthenticityToken error 🎉

Thanks again!

Collapse
 
akhil profile image
Akhil Naidu

Rather than modifying the host file, what about changing it in the container-compose.yml?

Thread Thread
 
markomannux profile image
markomannux

If I had a DNS record pointing to my environment, that would be certainly better.

For a local setup for testing purposes without DNS, I think the hosts file record is the only viable option.

Thanks again!

Collapse
 
markomannux profile image
markomannux

Thanks @akhil ! I'll try your suggestions as soon as possible and keep you posted.

Collapse
 
akhil profile image
Akhil Naidu

Hey, I even got a simple solution for you, this might sound a little bit awkward, but this is how it can be resolved easily.

While accessing Forem in the browser, I guess you are using: 127.0.0.1:3000
Rather than that try using: localhost:3000

I knew that your problem was resolved, but while you are installing Forem again in another VM or in VPS, there is no need of creating such a host record.

If it is a VPS, change APP_DOMAIN = a.b.c.d:3000

Collapse
 
markomannux profile image
markomannux

I think your suggestion for VPS will definetily work (I cannot try at the moment).

However I tried to access to my dev environment with localhost:3000 and still I get InvalidAuthenticityToken error. For now I will stick to the hosts entry