This is my user:
class User < ActiveRecord::Base
has_secure_password
end
This is how someone can authenticate via API:
module Api
class SessionsController < ApiController
def create
user = User.find_by_email(params[:user][:email])
if user && user.authenticate(params[:user][:password])
# some login logic
else
render json: {messages: user.errors.full_messages}, status: :unauthorized
end
end
end
end
If I pass an incorrect password, I get 401 Unauthorized as expected. However, user.errors is blank. How can I access has_secure_password authentication errors?
messages: "Invalid email or password"? - You are not validating any attributes, only that the user can be authenticated. AFAIKhas_secure_passwordprovides validations on create of object but just returns false when user cannot be authenticated.