Method: ApplicationHelper#current_user

Defined in:
app/helpers/application_helper.rb

#current_userUser?

Redefined Devise current_user helper. Additionally checks for deleted users - if the current user has been soft deleted, this will sign them out. As current_user is called on every page in the header, this has the effect of immediately signing the user out even if they’re signed in when their account is deleted.

Returns:



287
288
289
290
291
292
293
294
295
296
297
# File 'app/helpers/application_helper.rb', line 287

def current_user
  return nil unless defined?(warden)

  @current_user ||= warden.authenticate(scope: :user)
  if @current_user&.deleted? || @current_user&.community_user&.deleted?
    scope = Devise::Mapping.find_scope!(:user)
    logout scope
    @current_user = nil
  end
  @current_user
end