Last active
September 8, 2019 06:10
-
-
Save promisepreston/3c8832284329a1f3623fabed5233beda to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/services/authenticate_user.rb | |
class AuthenticateUser | |
def initialize(email, password) | |
@email = email | |
@password = password | |
end | |
def call | |
JsonWebToken.encode(user_id: user.id) if user | |
end | |
private | |
attr_accessor :email, :password | |
def user | |
user = User.find_by(email: email) | |
# return user if user && user.authenticate(password) | |
return user if user&.authenticate(@password) | |
errors.add(:user_authentication, 'invalid credentials') | |
nil | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment