Gaurav Shah
Gaurav Shah

Reputation: 5279

devise makes a db call on `authenticate_user!`

we use before_filter :authenticate_user

I was wondering about the following code:

  def serialize_from_session(key, salt)
      record = to_adapter.get(key)
      record if record && record.authenticatable_salt == salt
    end

Its in devise-3.1.0/lib/devise/models/authenticatable.rb Does devise make call to database for every request? or am I reading something wrong ?

Upvotes: 1

Views: 186

Answers (1)

sevenseacat
sevenseacat

Reputation: 25049

Yes, it does.

It will read the stored user data (user ID and authentication salt) from the session, then verify that a user in the database matches this stored data, by performing a lookup. The second part of that is what this code is doing.

Upvotes: 1

Related Questions