graphql_devise icon indicating copy to clipboard operation
graphql_devise copied to clipboard

Unable to set my message from #inactive_message method

Open vitaliiorlov opened this issue 1 year ago • 7 comments

Describe the bug

Hi! I have defined #active_for_authentication? method in the User model according to the Devise documentation which can return false when I would like to disable login for users.

def active_for_authentication?
  super && ...
end

To show the reason why the user cannot log in I should define #inactive_message method in User model.

def inactive_message
  "My message"
end

But it doesn't work with this gem because in Login mutation you have such conditions. Instead of my message, I saw a message that confirmation instructions were sent to my email address.

Steps to reproduce

  1. Define those methods in your User model:
def active_for_authentication?
  false
end

def inactive_message
  "My message"
end
  1. Try to log in.

Expected behavior

Show message from #inactive_message method. By the way, #unauthenticated_message method also exists. Maybe it is worth supporting this method too.

Thank you!

vitaliiorlov avatar Nov 02 '23 15:11 vitaliiorlov

Thank you for looking into this, @vitaliiorlov! I'll take a look asap. It looks like something that might be easy to fix

mcelicalderon avatar Nov 09 '23 01:11 mcelicalderon

@vitaliiorlov after taking a closer look at this, I see now that we based our implementation on DTA's implementation https://github.com/lynndylanhurley/devise_token_auth/blob/6b0659f18c678b319913d0fb053e96aa555857aa/app/controllers/devise_token_auth/sessions_controller.rb#L13

I still think this is something we can implement, but I need to take a longer look as it's not just removing something I thought we had overwritten. Also, looking at Devise's code https://github.com/search?q=repo%3Aheartcombo%2Fdevise%20inactive_message&type=code I'm not sure those messagesare easy to override? They return symbols and in one place it's interpolated. Could you please point to the docs where it's explained how to use this method?

mcelicalderon avatar Nov 15 '23 02:11 mcelicalderon

@mcelicalderon sure, here it is: https://github.com/heartcombo/devise/wiki/How-To:-Customize-user-account-status-validation-when-logging-in And I think they handle it there: https://github.com/heartcombo/devise/blob/e2242a95f3bb2e68ec0e9a064238ff7af6429545/lib/devise/failure_app.rb#L108

vitaliiorlov avatar Nov 15 '23 09:11 vitaliiorlov

Thank you for the link, @vitaliiorlov. So it is based on localized messages. I still think that's something we can implement

mcelicalderon avatar Nov 15 '23 15:11 mcelicalderon

Thank you @mcelicalderon! Looking forward for this enhancement.

vitaliiorlov avatar Nov 15 '23 17:11 vitaliiorlov

Hello @mcelicalderon !

Any news regarding this?

Thank you!

vitaliiorlov avatar Nov 30 '23 21:11 vitaliiorlov

@vitaliiorlov we haven't had the chance to work on this yet and we'll do it as soon as possible. You are welcome to propose an MR for us to review if you have the time before we do

mcelicalderon avatar Dec 01 '23 04:12 mcelicalderon