Answer the question
In order to leave comments, you need to log in
How to make multiple sessions for one user in Devise(:database_authenticatable)?
Hello!
I am developing an apishka for a rail application (backend for a mobile client), in which authorization has long been performed by Devise. Everything is clear with the web version, it has been working like clockwork for a long time - a user can have several active sessions on different computers. But with mobile authorization, everything seems to be bad, at least for me. There is a basic User model:
devise :database_authenticatable,
:registerable,
:recoverable,
:rememberable,
:trackable,
:validatable,
:token_authenticatable,
:omniauthable
before_filter :authenticate_user!, except: [ :new, :sign_in ]
def sign_in
if params[:user][:email].blank? and params[:user][:name].blank?
return render status: 404, json: { error: "You must specify email or name"}
end
if params[:user][:email]
user = User.find_by_email(email: params[:user][:email].downcase)
elsif params[:user][:name]
user = User.where("lower(name) = ?", params[:user][:name].downcase).first
end
if user.blank?
return render status: 404, json: { error: "User not found" }
end
if user.valid_password? params[:user][:password]
user.reset_authentication_token!
return render status: 200, json: { token: user.authentication_token }
else
return render status: 401, json: { error: "Invalid password" }
end
end
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question