mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Logout could fail due to cached user (#17325)
Logging out failed when the current user was cached by an instance of `Auth::DefaultCurrentUserProvider` and `#log_off_user` was called on a different instance of that class. Co-authored-by: Sam <sam.saffron@gmail.com>
This commit is contained in:
@@ -25,6 +25,7 @@ require_relative '../route_matcher'
|
||||
class Auth::DefaultCurrentUserProvider
|
||||
|
||||
CURRENT_USER_KEY ||= "_DISCOURSE_CURRENT_USER"
|
||||
USER_TOKEN_KEY ||= "_DISCOURSE_USER_TOKEN"
|
||||
API_KEY ||= "api_key"
|
||||
API_USERNAME ||= "api_username"
|
||||
HEADER_API_KEY ||= "HTTP_API_KEY"
|
||||
@@ -102,6 +103,7 @@ class Auth::DefaultCurrentUserProvider
|
||||
def initialize(env)
|
||||
@env = env
|
||||
@request = Rack::Request.new(env)
|
||||
@user_token = env[USER_TOKEN_KEY]
|
||||
end
|
||||
|
||||
# our current user, return nil if none is found
|
||||
@@ -139,7 +141,7 @@ class Auth::DefaultCurrentUserProvider
|
||||
limiter = RateLimiter.new(nil, "cookie_auth_#{request.ip}", COOKIE_ATTEMPTS_PER_MIN , 60)
|
||||
|
||||
if limiter.can_perform?
|
||||
@user_token = begin
|
||||
@env[USER_TOKEN_KEY] = @user_token = begin
|
||||
UserAuthToken.lookup(
|
||||
auth_token,
|
||||
seen: true,
|
||||
@@ -263,7 +265,7 @@ class Auth::DefaultCurrentUserProvider
|
||||
end
|
||||
|
||||
def log_on_user(user, session, cookie_jar, opts = {})
|
||||
@user_token = UserAuthToken.generate!(
|
||||
@env[USER_TOKEN_KEY] = @user_token = UserAuthToken.generate!(
|
||||
user_id: user.id,
|
||||
user_agent: @env['HTTP_USER_AGENT'],
|
||||
path: @env['REQUEST_PATH'],
|
||||
|
||||
Reference in New Issue
Block a user