Rails apiSort Order

Rails API: Error Handling for Session Endpoint - [039]

In this episode we make a 1 line change to our controller to fix some issues on the front-end.

In app/controllers/v1/sessions_controller.rb . We need to make one change in the create action.

def create  @user = User.where(email: params[:email]).first  if @user&.valid_password?(params[:password])    jwt = JWT.encode(      {user_id: @user.id, exp: (Time.now + 2.weeks).to_i},      Rails.application.secrets.secret_key_base,      'HS256'    )    render :create, status: :created, locals: { token: jwt }  else    # from:     # head(:unauthorized)    # to:    render json: { error: 'invalid_credentials' }, status: :unauthorized  endend

That's it! This is a quick episode! Watch how this code fixes our issue in the next React Intermediate episode.