Class: Users::SessionsController

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

Overview

Extend the devise sessions controller to support JSON based authentication and issuing a JWT.

Instance Method Summary collapse

Instance Method Details

#create {|resource| ... } ⇒ Object

Yields:

  • (resource)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/users/sessions_controller.rb', line 7

def create

  # This is the default behavior from devise - view the sessions controller source:
  # https://github.com/plataformatec/devise/blob/master/app/controllers/devise/sessions_controller.rb#L16
  self.resource = warden.authenticate!(auth_options)
  (resource_name, resource)
  yield resource if block_given?

  # Here we're deviating from the standard behavior by issuing our JWT
  # to any JS based client.
  token = AuthToken.new(payload: { user_id: resource.id }).token
  # contents = AuthToken.new(token: token).decoded

  render json: {user: resource.email, token: token}

end