Class: DeviseMultipleTokenAuth::TokenAuthenticationController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/devise_multiple_token_auth/token_authentication_controller.rb

Instance Method Summary collapse

Instance Method Details

#loginObject



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

def 
  email = params[:email] || params[:username]
  password = params[:password]
  user = User.find_by(email: email)
  if user.present? && user.valid_password?(params[:password])
    device = user.create_device
    render json: {auth_token: device.auth_token}, status: :ok
  else
    render json: {error: 'Invalid credentials', code: '401'}, status: :unauthorized
  end
end

#logoutObject



19
20
21
22
# File 'app/controllers/devise_multiple_token_auth/token_authentication_controller.rb', line 19

def logout
  @device.destroy if @device
  head :no_content
end