Class: JwtAuthEngine::SessionsController

Inherits:
ApplicationController show all
Includes:
Serializable, Tokenizable
Defined in:
app/controllers/jwt_auth_engine/sessions_controller.rb

Overview

Login and logout endpoints for session token lifecycle.

Instance Method Summary collapse

Methods included from ResponseRenderable

#render_internal_server_error, #render_success, #render_unauthorized, #render_validation_error

Instance Method Details

#loginObject

── POST /login ──────────────────────────────────────────────────────────



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/jwt_auth_engine/sessions_controller.rb', line 12

def 
  result = LoginService.new(login_params: ).call

  return render_unauthorized(result[:error]) unless result[:success]

  auth_model_instance = result[JwtAuthEngine.auth_model_name]

  render_success(
    message: 'Login successful.',
    JwtAuthEngine.auth_model_name => serialize_auth_model_instance(auth_model_instance),
    **issue_tokens(auth_model_instance)
  )
end

#logoutObject

── DELETE /logout ───────────────────────────────────────────────────────── Stateless logout: the client should discard tokens.



28
29
30
# File 'app/controllers/jwt_auth_engine/sessions_controller.rb', line 28

def logout
  render_success(status: :no_content)
end