Class: Authr::SessionsController

Inherits:
Devise::SessionsController
  • Object
show all
Defined in:
app/controllers/authr/sessions_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/authr/sessions_controller.rb', line 3

def create
  respond_to do |format|
    format.html { super }
    format.json do
      if warden.authenticate(auth_options)
        self.resource = warden.authenticate!(auth_options)
        (resource_name, resource)
        data = {
          token: self.resource.authentication_token,
          email: self.resource.email
        }
        render json: data, status: 201
      else
        render json: { error: :invalid }, status: 401
      end
    end
  end
end