Can I execute custom actions after successful sign in with Devise?

前端 未结 5 2397
春和景丽
春和景丽 2020-12-08 15:01

I have an app that has basic Devise authentication. After sign in, I would like to look up the user account (user belongs_to account, account has_many users), and store tha

5条回答
  •  不知归路
    2020-12-08 15:56

    i'm using rails 5 and devise 4.2.1, my solution is overide devise function on user model:

    def after_database_authentication
        # here's the custom code
    end
    

    and the user model will look like this:

    class User < ApplicationRecord
        devise :database_authenticatable, :registerable,
            :recoverable, :rememberable, :trackable, :validatable,
            :timeoutable, :lockable
        def after_database_authentication
            # here's the custom code
        end
    end
    

    it was called just after the authentication, i read it from this devise documentation, hope this could help

提交回复
热议问题