class AuthenticationController

Public Instance Methods

login() click to toggle source

POST /auth/login

# File lib/generators/jwt_rails/templates/authentication_controller.rb, line 5
def login
  @user = User.find_by_email(params[:email])
  if @user&.authenticate(params[:password])
    token = JsonWebToken.encode(user_id: @user.id)
    time = Time.now + 24.hours.to_i
    render json: { token: token, exp: time.strftime("%m-%d-%Y %H:%M"),
                   username: @user.username }, status: :ok
  else
    render json: { error: 'unauthorized' }, status: :unauthorized
  end
end

Private Instance Methods

login_params() click to toggle source
# File lib/generators/jwt_rails/templates/authentication_controller.rb, line 19
def login_params
  params.permit(:email, :password)
end