We've moved discussions to Discord

Not able to Login to my App

Subrat Rout
I just installed the Jumpstart and started working on it. Initially I was able to login few times, but now I am not able to login. On browser console I am seeing following error. I am using Chrome, Version 83.0.4103.106 (Official Build) (64-bit) on my Mac. However, I am able to log in using Safari browser. Not sure what is going on.

rails-ujs.js:216 POST https://example.com/users/sign_in 422 (Unprocessable Entity)
s.ajax @ application-d9cda7f83d6120b26237.js:2
s.handleRemote @ application-d9cda7f83d6120b26237.js:2
(anonymous) @ application-d9cda7f83d6120b26237.js:2

Chris Oliver
What do your Rails logs show when it renders the 422?
Subrat Rout
I am receiving following error on puma.error.log

ba83585]   Parameters: {"authenticity_token"=>"7N30ovc4TxV6q6IjMpSaqpd2CyjpYpHNuIVNms8Z+TjUgC1tFzqB3XemV/qq3+5WdnkRV2qVoiFHRLbHsn1Sqw==", "user"=>{"email"=>"[FILTERED]", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Log in"}
W, [2020-06-19T18:55:22.812371 #18403]  WARN -- : [06148ead-5cf1-4682-b451-9e765ba83585] HTTP Origin header (https://example.com) didn't match request.base_url (http://example.com)
I, [2020-06-19T18:55:22.812792 #18403]  INFO -- : [06148ead-5cf1-4682-b451-9e765ba83585] Completed 422 Unprocessable Entity in 1ms (Allocations: 430)
F, [2020-06-19T18:55:22.814305 #18403] FATAL -- : [06148ead-5cf1-4682-b451-9e765ba83585]
[06148ead-5cf1-4682-b451-9e765ba83585] ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken):
[06148ead-5cf1-4682-b451-9e765ba83585]
[06148ead-5cf1-4682-b451-9e765ba83585] actionpack (6.0.3.1) lib/action_controller/metal/request_forgery_protection.rb:215:in `handle_unverified_request'
[06148ead-5cf1-4682-b451-9e765ba83585] actionpack (6.0.3.1) lib/action_controller/metal/request_forgery_protection.rb:247:in `handle_unverified_request'
[06148ead-5cf1-4682-b451-9e765ba83585] devise (4.7.1) lib/devise/controllers/helpers.rb:255:in `handle_unverified_request'
[06148ead-5cf1-4682-b451-9e765ba83585] actionpack (6.0.3.1) lib/action_controller/metal/request_forgery_protection.rb:242:in `verify_authenticity_token'
Chris Oliver
Looks like it's because of:

HTTP Origin header (https://example.com) didn't match request.base_url (http://example.com)

Seems like you've got something going on there (https vs http) that's misconfigured in your setup.
Chris Oliver
Could be your NGINX / Puma proxy config isn't passing protocols over: https://github.com/rails/rails/issues/22965
Subrat Rout
I already have added following to my nginx.conf but still the issue persists.

upstream puma {
  server unix:///home/subrat/myapp/shared/tmp/sockets/medicaldevicehub-puma.sock;
}
server {
  listen 80 default_server deferred;
  server_name medicaldevicehub.com;
  listen [::]:80;

  root /home/subrat/medicaldevicehub/current/public;
  access_log /home/subrat/medicaldevicehub/current/log/nginx.access.log;
  error_log /home/subrat/medicaldevicehub/current/log/nginx.error.log info;

  location ~ ^/(assets|packs)/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @puma;
  location @puma {
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Ssl on;
    proxy_set_header X-Forwarded-Port 443;
    proxy_set_header  X-Forwarded-Port $server_port;
    proxy_redirect off;

    proxy_pass http://puma;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 100m;
  keepalive_timeout 10;
}
Chris Oliver
You look like you're setting duplicate headers for the port, and I don't see X-Forwarded-Proto which is what most people use.
Subrat Rout
Took out the duplicate headers port and added X-Forwarded-Proto. The issue still persists.  Kindly help.

Here is the snippet.

  location @puma {
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Ssl on;
    proxy_set_header X-Forwarded-Port $server_port;
    proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
    proxy_redirect off;

    proxy_pass http://puma;
  }
Thanks
Subrat Rout
I got it working. When I installed Let's-encrypt ssl it was messing up with ngnix.conf file and making some unwanted changes. Thank you Chris.
Notifications
You’re not receiving notifications from this thread.