Class: RailsJwtAuth::SessionsController

Inherits:
ApplicationController
  • Object
show all
Includes:
ParamsHelper, RenderHelper
Defined in:
app/controllers/rails_jwt_auth/sessions_controller.rb

Instance Method Summary collapse

Methods included from RenderHelper

#render_204, #render_404, #render_422, #render_registration, #render_session

Instance Method Details

#createObject



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/rails_jwt_auth/sessions_controller.rb', line 6

def create
  user = find_user

  if !user
    render_422 session: [{error: :invalid_session}]
  elsif user.respond_to?('confirmed?') && !user.confirmed?
    render_422 session: [{error: :unconfirmed}]
  elsif user.authenticate(session_create_params[:password])
    render_session generate_jwt(user), user
  else
    render_422 session: [{error: :invalid_session}]
  end
end

#destroyObject



20
21
22
23
24
25
26
27
# File 'app/controllers/rails_jwt_auth/sessions_controller.rb', line 20

def destroy
  return render_404 unless RailsJwtAuth.simultaneous_sessions > 0

  authenticate!
  payload = JwtManager.decode_from_request(request)&.first
  current_user.destroy_auth_token payload['auth_token']
  render_204
end