3
votes

I am using Devise for authentication in my rails app. There are two devise models in the app, admin and customer.

Customer model uses mobile_number for authentication instead of the usual email_id field. However, the admin field uses email_id for authentication.

Now, the issue I am facing is related to the default flash messages shown by devise.

Consider, when a user enters invalid login credentials, the message is

'Invalid email or password'

I want to customize this message based on models. So, if admin enters incorrect credentials, message is:

'Invalid email or password'

If customer enters the same, it is:

'Invalid mobile number or password'
1

1 Answers

3
votes

Currently Devise gem supports different kinds of locale files like for English, Arabic, Chinese etc for showing all flash messages related to Devise authentication in different languages.

Refer this link. Choose the English version. In that you could see when you need to show invalid email or password flash message. So the solution is,

en:
  devise:
    failure:
      customer:
        invalid: 'Welcome user, you are signed in.'
        not_found_in_database: 'Welcome user, you are signed in.'
      admin:
        invalid: 'Invalid mobile number or password'
        not_found_in_database: 'Invalid mobile number or password'

Hope this helps :)