Sha256: f729587d754764871fb635e3db7a1e1c62fe8e8407b11e909c9f043b3c7a11f0

Contents?: true

Size: 1.16 KB

Versions: 6

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

module Ibrain
  module Auth
    class User < Ibrain::Base
      include Devise::JWT::RevocationStrategies::JTIMatcher

      attr_accessor :jwt_token

      self.table_name = Ibrain::Auth::Config.user_table_name

      devise :database_authenticatable, :registerable,
             :recoverable, :validatable, :timeoutable,
             :jwt_authenticatable, jwt_revocation_strategy: self

      def jwt_payload
        # for hasura
        hasura_keys = {
            'https://hasura.io/jwt/claims': {
            'x-hasura-allowed-roles': [role],
            'x-hasura-default-role': role,
            'x-hasura-user-id': id.to_s
          }
        }

        super.merge({ 'role' => role }, hasura_keys)
      end

      class << self
        def ibrain_find(params, available_columns)
          matched_value = params[:username] || params[:email]

          if matched_value.present?
            query = available_columns.map do |column_name|
              <<~RUBY
                #{column_name} = '#{matched_value}'
              RUBY
            end.join(' OR ')

            where(query).first
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ibrain-auth-0.1.7 app/models/ibrain/auth/user.rb
ibrain-auth-0.1.6 app/models/ibrain/auth/user.rb
ibrain-auth-0.1.5 app/models/ibrain/auth/user.rb
ibrain-auth-0.1.4 app/models/ibrain/auth/user.rb
ibrain-auth-0.1.3 app/models/ibrain/auth/user.rb
ibrain-auth-0.1.2 app/models/ibrain/auth/user.rb