After I press the button to "sign in" on https://myapp.com/users/sign_in, the following error appears:
ActionController::InvalidAuthenticityToken in Devise::SessionsController#create
regardless of the existing user's credentials.
If I press the button to sign in on http://myapp.com/users/sign_in, the user signs in and the application seems to work smoothly, except the user cannot create posts under HTTPs too.
I want to make devise authentication work under SSL.
routes.rb:
devise_for :users
application_controller.rb:
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
end
user.rb:
class User < ApplicationRecord
devise :database_authenticatable, :recoverable, :rememberable, :registerable, :trackable, :validatable
end
- I have the
<%= csrf_meta_tags %>
in the head - I cleared the cookies in browsers
- I tried
protect_from_forgery with: :null_session
instead ofprotect_from_forgery with: :exception
in app/controllers/application_controller.rb - I tried to put
<%= hidden_field_tag :authenticity_token, form_authenticity_token %>
in theform_for
for new session - I tried
devise_for :users, :controllers => { :sessions => "users/sessions" }
in root I tried to add
config.to_prepare { Devise::SessionsController.force_ssl } config.to_prepare { Devise::RegistrationsController.force_ssl } config.to_prepare { Devise::PasswordsController.force_ssl }
in config/environments/production.rb