Sha256: 6f1b091d271e5bdb099e56861fdccd04ba097cd2c60f7405a38e8bf911c44a96

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

# Response your own data structure

Not happy with the default response? Do not worry, you can override it easily.

## Sign In Response

To custom your sign in response data structure, you should override the method `respond_to_create`.

```rb
# frozen_string_literal: true

module Api
  class AuthController < AuthRails::Api::AuthController
    private

    def respond_to_create(data)
      render json: {
        profile: CurrentAuth.user,
        tokens: {
          auth_token: data[:access_token],
          refresh_token: data[:refresh_token]
        }
      }
    end
  end
end
```

If your response for refresh token action is the same, make this as its alias.

```rb
alias respond_to_refresh respond_to_create
```

## Refresh Response

To custom your refresh action response data structure, you should override the method `respond_to_refresh`.

```rb
# frozen_string_literal: true

module Api
  class AuthController < AuthRails::Api::AuthController
    private

    def respond_to_refresh(data)
      render json: {
        profile: CurrentAuth.user,
        tokens: {
          auth_token: data[:access_token],
          refresh_token: data[:refresh_token]
        }
      }
    end
  end
end
```

In case your sign in action's response is the same, make this as its alias.

```rb
alias respond_to_create respond_to_refresh
```

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
auth_rails-1.1.2 docs/src/customization/custom-response.md
auth_rails-1.1.1 docs/src/customization/custom-response.md