ruby-on-railsrubysorcery

Ruby on Rails - Sorcery override login method


I have a user table with guest column(boolean) to distinguish user's identity. I don't want user with guest? => true able to login. Is it possible to override Sorcery's login method?

I want it work like User.where(guest: false).authenticate(email, password)

Another way I'm thinking is to separate User and GuestUser using polymorphic association. However, I don't really want to create GuestUser with same columns as User.

Please give me some suggestions.


Solution

  •   # find specific user and check guest or not
      user = User.find_by_email(email)
      if user && user.guest == false
         User.authenticate(email, password)
      end