Class: Tokenable::TokensController

Inherits:
ActionController::API
  • Object
show all
Includes:
Authable
Defined in:
lib/tokenable/controllers/tokens_controller.rb

Instance Method Summary collapse

Methods included from Authable

#current_user, #require_tokenable_user!, #user_signed_in?

Instance Method Details

#createObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/tokenable/controllers/tokens_controller.rb', line 11

def create
  user = Tokenable::Config.user_class.from_tokenable_params(params)
  raise Tokenable::Unauthorized, 'No user returned by strategy' unless user

  response = {
    data: {
      token: token_from_user(user),
      user_id: user.id,
    },
  }

  render json: response, status: 201
end