Sha256: 1b4e6d40e5f2f4e0a8e1d1e532d0c6a7f1bcbcd6df4b260798c74b6378838bed

Contents?: true

Size: 1.07 KB

Versions: 6

Compression:

Stored size: 1.07 KB

Contents

class Ishapi::Users::SessionsController < Devise::SessionsController
  skip_before_action :verify_authenticity_token

  def create
    self.resource = warden.authenticate!(auth_options)
    set_flash_message!(:notice, :signed_in)
    sign_in(resource_name, resource)
    yield resource if block_given?
    # respond_with resource, location: after_sign_in_path_for(resource)

    ## Send the jwt to client
    @current_user = resource
    @jwt_token = encode(user_id: @current_user.id.to_s)
    @profile = @current_user.profile
    render 'ishapi/users/login', format: :json, layout: false
  end

  private

  ## copy-pasted from application_controller
  ## jwt
  def decode(token)
    decoded = JWT.decode(token, Rails.application.secrets.secret_key_base.to_s)[0]
    HashWithIndifferentAccess.new decoded
  end

  ## copy-pasted from application_controller
  ## jwt
  def encode(payload, exp = 48.hours.from_now) # @TODO: definitely change, right now I expire once in 2 days.
    payload[:exp] = exp.to_i
    JWT.encode(payload, Rails.application.secrets.secret_key_base.to_s)
  end


end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ishapi-0.1.8.194 app/controllers/ishapi/users/sessions_controller.rb
ishapi-0.1.8.193 app/controllers/ishapi/users/sessions_controller.rb
ishapi-0.1.8.192 app/controllers/ishapi/users/sessions_controller.rb
ishapi-0.1.8.191 app/controllers/ishapi/users/sessions_controller.rb
ishapi-0.1.8.190 app/controllers/ishapi/users/sessions_controller.rb
ishapi-0.1.8.189 app/controllers/ishapi/users/sessions_controller.rb