mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
FIX: Rescue from readonly errors when looking up auth tokens.
Since this is rare, we don't want to check for `Discourse.pg_readonly_mode?` on every request since we have to reach for Redis. Instead, just rescue the error here.
This commit is contained in:

committed by
Alan Guo Xiang Tan

parent
81e6bc7a0f
commit
d3c972c30c
@ -93,11 +93,17 @@ class Auth::DefaultCurrentUserProvider
|
||||
limiter = RateLimiter.new(nil, "cookie_auth_#{request.ip}", COOKIE_ATTEMPTS_PER_MIN , 60)
|
||||
|
||||
if limiter.can_perform?
|
||||
@user_token = UserAuthToken.lookup(auth_token,
|
||||
seen: true,
|
||||
user_agent: @env['HTTP_USER_AGENT'],
|
||||
path: @env['REQUEST_PATH'],
|
||||
client_ip: @request.ip)
|
||||
@user_token = begin
|
||||
UserAuthToken.lookup(
|
||||
auth_token,
|
||||
seen: true,
|
||||
user_agent: @env['HTTP_USER_AGENT'],
|
||||
path: @env['REQUEST_PATH'],
|
||||
client_ip: @request.ip
|
||||
)
|
||||
rescue ActiveRecord::ReadOnlyError
|
||||
nil
|
||||
end
|
||||
|
||||
current_user = @user_token.try(:user)
|
||||
end
|
||||
|
Reference in New Issue
Block a user