Sha256: e0f87376bf8ce2ddb3ef9a429ff4d6ffcdee3a3ea0e74b768c81d5130a4b1c3e

Contents?: true

Size: 816 Bytes

Versions: 2

Compression:

Stored size: 816 Bytes

Contents

# Custom retrieve resource

Sometimes, your logic to retrieve user is too complex. It is not simple `User.find_by(email: identifier)`.

```rb
# frozen_string_literal: true

Rails.application.config.to_prepare do
  AuthRails.configure do |config|
    config.resource_class = User
    config.identifier_name = :username
    config.dig_params = ->(params) { params[:identifier] }

    config.retrieve_resource = lambda { |identifier|
      User.where(email: identifier)
          .or(User.where(username: identifier))
          .first
    }
  end
end
```

## config.identifier_name

This will be used to set to `sub` of JWT's `payload`.

## config.dig_params

To extract `identifier` for the `retrieve_resource` config.

## config.retrieve_resource

This is where you define how to get your resource to do the sign in.

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
auth_rails-1.1.2 docs/src/customization/complex-retrieve-resource.md
auth_rails-1.1.1 docs/src/customization/complex-retrieve-resource.md