gpt4 book ai didi

ruby-on-rails - devise_token_auth 和 Rails 5 - 索引错误 : string not matched

转载 作者:行者123 更新时间:2023-12-04 06:36:52 28 4
gpt4 key购买 nike

我正在尝试使用 devise_token_auth 登录现有用户版本0.1.38 ,但我正在打 IndexError: string not matched在图书馆的sessions_controller .

IndexError (string not matched):

devise_token_auth (0.1.38) app/controllers/devise_token_auth/sessions_controller.rb:37:in `[]='
devise_token_auth (0.1.38) app/controllers/devise_token_auth/sessions_controller.rb:37:in `create'
actionpack (5.0.0) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
actionpack (5.0.0) lib/abstract_controller/base.rb:188:in `process_action'
actionpack (5.0.0) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (5.0.0) lib/abstract_controller/callbacks.rb:20:in `block in process_action'

相关代码来自 sessions_controller是:
  if @resource and valid_params?(field, q_value) and @resource.valid_password?(resource_params[:password]) and (!@resource.respond_to?(:active_for_authentication?) or @resource.active_for_authentication?)
# create client id
@client_id = SecureRandom.urlsafe_base64(nil, false)
@token = SecureRandom.urlsafe_base64(nil, false)

# !! Next line is line 37 with the error !!
@resource.tokens[@client_id] = {
token: BCrypt::Password.create(@token),
expiry: (Time.now + DeviseTokenAuth.token_lifespan).to_i
}
@resource.save

sign_in(:user, @resource, store: false, bypass: false)

我已添加 devise_token_auth到现有项目,因此我很可能在 tokens 中创建了错误数据柱子。我尝试了各种默认方式 token json 导入我现有的用户,包括模仿 sessions_controller 中的代码.
add_column :users, :tokens, :json, null: false, default: {}

User.reset_column_information
client_id = SecureRandom.urlsafe_base64(nil, false)
token = SecureRandom.urlsafe_base64(nil, false)

User.find_each do |user|
user.uid = user.email
user.provider = 'email'
user.tokens[client_id] = {
token: BCrypt::Password.create(token),
expiry: (Time.now + DeviseTokenAuth.token_lifespan).to_i
}
user.save!
end

我在 issue #101 中看到了这个,但没有具体的决议。知道我哪里出错了吗?

最佳答案

原来我需要设置 tokensnil ,然后设计将负责为我设置。我在 this devise issue. 中找到了答案

def change
add_column :users, :provider, :string, null: false, default: "email"
add_column :users, :uid, :string, null: false, default: ""
add_column :users, :tokens, :text

reversible do |direction|
direction.up do
User.find_each do |user|
user.uid = user.email
user.tokens = nil
user.save!
end
end
end

add_index :users, [:uid, :provider], unique: true
end

关于ruby-on-rails - devise_token_auth 和 Rails 5 - 索引错误 : string not matched,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38424068/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com