Class: Api::V1::AuthenticationController

Inherits:
BaseController
  • Object
show all
Defined in:
lib/generators/jwt_api/templates/api/v1/authentication_controller.rb

Instance Method Summary collapse

Instance Method Details

#authenticate_userObject



6
7
8
9
10
11
12
13
# File 'lib/generators/jwt_api/templates/api/v1/authentication_controller.rb', line 6

def authenticate_user
  user = User.find_for_database_authentication(email: params[:email])
  if !user.nil? && user.valid_password?(params[:password])
    render json: payload(user)
  else
    render json: { errors: ['Invalid Username/Password'] }, status: :unauthorized
  end
end

#logoutObject

Invalidate users JWT, logout user



16
17
18
19
20
21
22
23
# File 'lib/generators/jwt_api/templates/api/v1/authentication_controller.rb', line 16

def logout
  @current_user.jti = SecureRandom.uuid
  if @current_user.save
    render json: { success: true }
  else
    render json: { success: false }, status: :unprocessable_entity
  end
end