graphql-devise / graphql_devise

GraphQL interface on top devise_token_auth
MIT License
200 stars 39 forks source link

Unable to set my message from #inactive_message method #265

Open vitaliiorlov opened 11 months ago

vitaliiorlov commented 11 months ago

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


2. 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!
mcelicalderon commented 10 months ago

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

mcelicalderon commented 10 months ago

@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?

vitaliiorlov commented 10 months ago

@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

mcelicalderon commented 10 months ago

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

vitaliiorlov commented 10 months ago

Thank you @mcelicalderon! Looking forward for this enhancement.

vitaliiorlov commented 10 months ago

Hello @mcelicalderon !

Any news regarding this?

Thank you!

mcelicalderon commented 10 months ago

@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