Module: CowAuth::TokenAuth::SessionEndpoints

Extended by:
ActiveSupport::Concern
Defined in:
lib/cow_auth/token_auth/session_endpoints.rb

Instance Method Summary collapse

Instance Method Details

#createObject



8
9
10
11
12
13
14
15
16
# File 'lib/cow_auth/token_auth/session_endpoints.rb', line 8

def create
  @user = authentication_class.find_by(email: params[:email])
  if @user.try(:authenticate_with_password, params[:password])
    @user.create_auth_token
    render json: self., status: :ok
  else
    raise CowAuth::NotAuthenticatedError.new('Invalid user credentials.')
  end
end

#destroyObject



18
19
20
21
22
23
24
# File 'lib/cow_auth/token_auth/session_endpoints.rb', line 18

def destroy
  if @current_user.try(:destroy_auth_token)
    head :no_content
  else
    raise CowAuth::NotAuthenticatedError.new('Could not sign user out.')
  end
end