我尝试使用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'
1}}。
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
列中创建了错误数据。我尝试了各种方法将sessions_controller
json默认为现有用户,包括模仿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
中的代码。
for i in xrange(MAXFDS):
pass
我在issue #101中看到了这一点,但没有具体的解决方案。我知道哪里出错了?
答案 0 :(得分:4)
事实证明我需要将tokens
设置为nil
,然后设计将负责为我设置。我在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