developer tip

Devise Secret Key가 설정되지 않았습니다.

optionbox 2020. 8. 23. 08:58
반응형

Devise Secret Key가 설정되지 않았습니다.


관리 백엔드 용 Active Admin gem을 사용하여 Rails 4 앱을 개발 중입니다. Active Admin은 사용자 인증을 위해 Devise를 사용합니다. 이제 capistranoVPS 서버에서 사용하여 앱을 배포하려고 하면 다음 오류가 발생합니다.

rake aborted!
Devise.secret_key was not set. Please add the following to your Devise initializer:
config.secret_key = '-- secret key --'

Google 검색은이 오류에 대해 많은 역할을하지 않습니다. 오류가 발생하는 이유는 무엇입니까? devise이러한 구성 키를 설정할 위치를 찾을 수 없으므로 이니셜 라이저에 비밀 키를 추가해야합니까 initializers/devise.rb?


나는 bundle update오늘 아침에 뛰었고 같은 오류가 발생하기 시작했습니다.

나는 그것을 줄로 추가 config/initializers/devise.rb했고 오류가 수정되었습니다.

이것은 그것을 소개 커밋것 같습니다 .


Rails 4.1 및 Devise 3.2.4에서 나를 위해 일한 것은 다음과 config/initializers/devise.rb같습니다.

config.secret_key = ENV['DEVISE_SECRET_KEY'] if Rails.env.production?

현재 고안 3.2.3 에 키 설정 위치 기본값 레일 4 + 응용 프로그램에 대한 YourAppName :: Application.config.secret_key_base가 발견에서 설정 / 초기화 / secret_token.rb


이것은 내 문제를 해결했습니다.

아래 코드를 config / initializers / devise.rb 파일에 추가 하십시오.

config.secret_key = '-- secret key --' 

'-secret key--'를 자신의 키로 바꿉니다. 보안을 위해 ENV 변수에 저장하는 것이 좋습니다.


에 따라 변경 내역 :

Devise는 Rails 4+ 애플리케이션의 secret_key_base를 secret_key로 사용합니다. devise.rb 이니셜 라이저를 변경하여이를 변경하고 자신의 비밀을 사용할 수 있습니다.

나는 갔었다 config/secrets.ymlproduction 값을 변경했습니다 .

전에:

production: 
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

후:

production: 
  secret_key_base: string of charaters

물론, 나중에 설정하게 될 환경 변수로 설정해야합니다. 사용하여 내 문자열을 얻었습니다 bundle exec rake secret.


당신이 뛰지 않았을까요 rails g devise:install?

rails generate devise User이전 명령없이 실행 하면이 문제가 발생합니다.


에서 config/initializers/devise.rbI 넣어 :

config.secret_key = ENV["SECRET_KEY_BASE"] if Rails.env.production?

다음과 같이 넣으면

$ heroku config

secret_key_base모드에 대한가 표시 됩니다 production.


이 추악한 접근 방식으로 초기화 문제를 해결합니다.

config.secret_key = 'some1234keyq23' if Rails.env == 'production'

config / initializers / devise.rb에서 이제 프로덕션과 개발에서 작동합니다!


다음 사항 config\initializers\secret_token.rb있는지 확인하십시오 .

YourAppName::Application.config.secret_token

그것은해야한다:

YourAppName::Application.config.secret_key_base

내 저장소를 git에서 새 컴퓨터에 복제했습니다. 그만큼

config/secrets.yml 

파일이 내 .gitignore 목록에 있으므로 해당 파일이 존재하지 않았고 Devise가 파일을 생성하지 않습니다.

파일을 추가 한 다음 다시 실행했습니다.

rails generate devise MODEL

그리고 그것은 작동했습니다.


I has same issue. The problem was caused by these lines in routes.rb:

devise_for :users, :skip => [:registrations]                                                   
as :user do
  get 'users/edit' => 'devise/registrations#edit', :as => 'edit_user_registration'              
  put 'users' => 'devise/registrations#update', :as => 'user_registration'                      
  get '/users/sign_out' => 'devise/sessions#destroy'                                            
end

I commented them and after that i run:

$ rails generate devise:install

And it has evaluated perfectly. And after that I uncommented routes.


Well, I have been following this post and tried almost everything here. I have added the key to devise.rb. But I was still getting the same error.

Maybe a stupid answer, but all I had to do was to push the devise.rb key to the repository.


Fix:

  1. In the production server:

    sudo -H nano /etc/environment
    
  2. Then in the file add:

    export SECRET_KEY_BASE="yourkey"
    export DEMO03_DATABASE_PASSWORD="yourpass"
    

    to set this permanently, and system wide (all users, all processes) add set variable

  3. In the local project devise.rb file:

    config.secret_key = ENV["SECRET_KEY_BASE"] if Rails.env.production?
    

Technical details:

  • Ubuntu 16.04
  • Devise (4.2.0)
  • rails 5.0.1
  • capistrano (3.7.1)

Ran into the same trouble with Rails 5.2.0 and Devise 4.4.1

Drop the following into /config/initializers/devise.rb

config.secret_key = Rails.application.credentials.secret_key_base

Trying to give a somewhat more complete answer to the ones above: As mentioned in the devise_auth_token gem's documentation

...Additionally, you can configure other aspects of devise by manually creating the traditional devise.rb file at config/initializers/devise.rb. Here are some examples of what you can do in this file:

Devise.setup do |config|   
# The e-mail address that mail will appear to be sent from   
# If absent, mail is sent from "please-change-me-at-config-initializers-devise@example.com"  
config.mailer_sender = "support@myapp.com"

# If using rails-api, you may want to tell devise to not use ActionDispatch::Flash   
# middleware b/c rails-api does not include it.   
# See: http://stackoverflow.com/q/19600905/806956  
config.navigational_formats = [:json] end

I had the same problem, and like metioned here, I created the devise initializer, and add the config.secret_key = ENV['DEVISE_SECRET_KEY'] line to it.


I do not know right solution but it's working. You can try it. I was cloned my project from my GitLab account and when I run in my local server, I have an error Message:

rake aborted! Devise.secret_key was not set. Please add the following to your Devise initializer: config.secret_key = '-- secret key --'

Open config/initializers/devise.rb and add this line

config.secret_key = '<%= ENV["SECRET_KEY_BASE"] %>'

This code line is solved my problem.

참고URL : https://stackoverflow.com/questions/18080910/devise-secret-key-was-not-set

반응형