Class: AuthenticationController

Inherits:
ApplicationController
  • Object
show all
Defined in:
lib/generators/auth/templates/authentication_controller.rb

Instance Method Summary collapse

Instance Method Details

#loginObject

POST /auth/login



7
8
9
10
11
12
13
14
15
# File 'lib/generators/auth/templates/authentication_controller.rb', line 7

def 
  @user = User.find_by_email(params[:email])
  if @user&.authenticate(params[:password])
    token = jwt_encode(user_id: @user.id)
    render json: { token: token }, status: :ok
  else
    render json: { error: 'unauthorized' }, status: :unauthorized
  end
end