class Api::V1::SessionsController < Devise::SessionsController
def create
if User.find_by(member_id: params[:user][:member_id])
self.resource = warden.authenticate!(auth_options)
sign_in(resource_name, resource)
resource.reset_authentication_token!
resource.save!
else
error :not_found
end
end
end
如何更改创建操作以确保只有具有角色的用户:“member
”才能登录。例如,管理员(user.role => :admin
)获得error => :unauthorized
答案 0 :(得分:0)
也许是这样的?
user = User.find_by(member_id: params[:user][:member_id])
return error :unauthorized unless user.role == :member
if user
...
else
...
end