Sha256: ff58869f75424a56553161a689433a68876eea53eb4f92834eb08693b3602e45

Contents?: true

Size: 803 Bytes

Versions: 29

Compression:

Stored size: 803 Bytes

Contents

# frozen_string_literal: true

module Shimmer
  module Auth
    module Authenticating
      extend ActiveSupport::Concern

      included do
        before_action :authenticate
        helper_method :current_user

        def require_login
          redirect_to login_path unless current_user
        end

        def current_user
          ::Current.user
        end

        def login(device:)
          ::Current.device = device
          cookies.encrypted[:device_token] = {value: device.token, expires: 2.years.from_now}
        end

        def logout
          cookies.delete :device_token
        end

        private

        def authenticate
          ::Current.device = cookies.encrypted[:device_token].presence&.then { |e| ::Device.find_by token: e }
        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
shimmer-0.0.41 lib/shimmer/auth/authenticating.rb
shimmer-0.0.40 lib/shimmer/auth/authenticating.rb
shimmer-0.0.39 lib/shimmer/auth/authenticating.rb
shimmer-0.0.38 lib/shimmer/auth/authenticating.rb
shimmer-0.0.37 lib/shimmer/auth/authenticating.rb
shimmer-0.0.36 lib/shimmer/auth/authenticating.rb
shimmer-0.0.35 lib/shimmer/auth/authenticating.rb
shimmer-0.0.34 lib/shimmer/auth/authenticating.rb
shimmer-0.0.33 lib/shimmer/auth/authenticating.rb
shimmer-0.0.32 lib/shimmer/auth/authenticating.rb
shimmer-0.0.31 lib/shimmer/auth/authenticating.rb
shimmer-0.0.30 lib/shimmer/auth/authenticating.rb
shimmer-0.0.29 lib/shimmer/auth/authenticating.rb
shimmer-0.0.28 lib/shimmer/auth/authenticating.rb
shimmer-0.0.27 lib/shimmer/auth/authenticating.rb
shimmer-0.0.26 lib/shimmer/auth/authenticating.rb
shimmer-0.0.25 lib/shimmer/auth/authenticating.rb
shimmer-0.0.24 lib/shimmer/auth/authenticating.rb
shimmer-0.0.23 lib/shimmer/auth/authenticating.rb
shimmer-0.0.22 lib/shimmer/auth/authenticating.rb