Class: RailsJwt::LoginController

Inherits:
ApplicationController show all
Defined in:
app/controllers/rails_jwt/login_controller.rb

Instance Method Summary collapse

Instance Method Details

#loginObject



6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/rails_jwt/login_controller.rb', line 6

def 
    user = RailsJwt.user_class.send("find_by_#{RailsJwt.user_id_attr}", params[:user_id])

    if user&.respond_to?(:active) && !user.active
        render status: :unauthorized
    elsif user&.authenticate(params[:password])
        token = JWT.encode(create_jwt_payload(user), RailsJwt.token_signature_key.call, 'HS256')
        render json: {jwt: token}
    else
        render status: :unauthorized
    end
end