0

Premise ruby 2.7.5 Rails 6.1.6.1 devise (4.8.1) devise_token_auth (1.2.0)

What I want to achieve When registering and logging in with devise-token-auth, I want to avoid including the id in the response.

Current registration response

{
    "status": "success",
    "data": {
        "id": 1,
        "provider": "email",
        "uid": "test@example.com",
        "allow_password_change": false,
        "name": null,
        "email": "test@example.com",
        "created_at": "2022-08-14T08:20:24.396Z",
        "updated_at": "2022-08-14T08:20:24.453Z"
    }
}

Ideal response

{
    "status": "success",
    "data": {
        "provider": "email",
        "uid": "test@example.com",
        "allow_password_change": false,
        "name": null,
        "email": "test@example.com",
        "created_at": "2022-08-14T08:20:24.396Z",
        "updated_at": "2022-08-14T08:20:24.453Z"
    }
}
tari
  • 11
  • 1
  • would be useful if you shared the code generating the response – dbugger Aug 19 '22 at 12:15
  • @dbugger [the code generating the response is in the gem](https://github.com/lynndylanhurley/devise_token_auth/blob/1a0483fbd12583810f21eb320abfa8b768724774/app/controllers/devise_token_auth/sessions_controller.rb#L24). What I'm lacking is any kind of effort at researching or solving the problem. – max Aug 19 '22 at 13:48
  • If the gem is returning that response, you'll probably need to write an initializer module to override that method. – Chiperific Aug 19 '22 at 14:49
  • 1
    @max what I was gently hinting at – dbugger Aug 19 '22 at 15:38
  • 1
    @Chiperific the way to override Devise controllers is by configuring the routes to point to your own subclass of the controller in question. https://stackoverflow.com/questions/3546289/override-devise-registrations-controller – max Aug 19 '22 at 15:40
  • @max, doesn't OP want to change the response from the Devise method they linked to? – Chiperific Aug 19 '22 at 16:05
  • @Chiperific yes. But its not done via an intializer. Its done by overriding the controller. – max Aug 19 '22 at 20:04

0 Answers0