Skip to content

Commit 1aa85fd

Browse files
authored
Using signed_id for finding and setting session record (rails#52504)
1 parent 26227e1 commit 1aa85fd

File tree

3 files changed

+3
-4
lines changed

3 files changed

+3
-4
lines changed

railties/lib/rails/generators/rails/authentication/authentication_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def enable_bcrypt
4747

4848
def add_migrations
4949
generate "migration CreateUsers email_address:string!:uniq password_digest:string! --force"
50-
generate "migration CreateSessions user:references token:token! ip_address:string user_agent:string --force"
50+
generate "migration CreateSessions user:references ip_address:string user_agent:string --force"
5151
end
5252
end
5353
end

railties/lib/rails/generators/rails/authentication/templates/controllers/concerns/authentication.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def resume_session
3030

3131
def find_session_by_cookie
3232
if token = cookies.signed[:session_token]
33-
Session.find_by(token: token)
33+
Session.find_signed(token)
3434
end
3535
end
3636

@@ -53,7 +53,7 @@ def start_new_session_for(user)
5353

5454
def set_current_session(session)
5555
Current.session = session
56-
cookies.signed.permanent[:session_token] = { value: session.token, httponly: true, same_site: :lax }
56+
cookies.signed.permanent[:session_token] = { value: session.signed_id, httponly: true, same_site: :lax }
5757
end
5858

5959
def terminate_session
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
class Session < ApplicationRecord
2-
has_secure_token
32
belongs_to :user
43
end

0 commit comments

Comments
 (0)