![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Allow staff users to impersonate your normal users: see what they see, only do what they can do.
This concept and code was extracted from Engine Yard Cloud, which we use when we want to help support a customer remotely.
This Rails engine currently supports the following Rails authentication systems:
When you are impersonating a user you see what they see, with a header section above:
Add the gem to your Rails application's Gemfile and run bundle
:
gem "user_impersonate"
Run the (sort of optional) generator:
bundle
rails g user_impersonate
This adds the following line within your config/routes.rb
:
mount UserImpersonate::Engine => "/impersonate", as: "impersonate_engine"
Include in your layout files support for flash[:error]
and flash[:notice]
, such as:
<p class="notice"><%= flash[:notice] %></p>
<p class="alert"><%= flash[:error] %></p>
Next, add the impersonation header to your layouts:
<% if current_staff_user %>
<%= render 'user_impersonate/header' %>
<% end %>
Next, add staff concept to your User model.
To test the engine out, make all users staff!
# app/models/user.rb
def staff?
true
end
# String to represent a user (email, name, etc)
def to_s
email
end
You can now go to http://localhost:3000/impersonate to see the list of users, except your own user account. If you impersonate one you will see the magic!
To support this Rails engine, you need to add some things.
current_user
helper within controllers & helperscurrent_user.staff?
- your User
model needs a staff?
to identify if the current user is allowed to impersonate other users; if missing, no user can access impersonation systemOne way to add this helper is to add a column to your User model:
rails g migration add_staff_flag_to_users staff:boolean
rake db:migrate db:test:prepare
You can override the bright red header by creating a app/views/user_impersonate/_header.html.erb
file (or whatever template system you like).
For example, the Engine Yard Cloud uses a header that looks like:
The app/views/user_impersonate/_header.html.haml
HAML partial for this header would be:
%div#impersonating
.impersonate-controls.page
.impersonate-info.grid_12
You (
%span.admin_name= current_staff_user
) are impersonating
%span.user_name= link_to current_user, url_for([:admin, current_user])
( User id:
%span.user_id= current_user.id
)
- if current_user.no_accounts?
( No accounts )
- else
( Account name:
%span.account_id= link_to current_user.accounts.first, url_for([:admin, current_user.accounts.first])
, id:
%strong= current_user.accounts.first.id
)
.impersonate-buttons.grid_12
= form_tag url_for([:ssh_key, :admin, current_user]), :method => "put" do
%span Support SSH Key
= select_tag 'public_key', options_for_select(current_staff_user.keys.map {|k| k})
%button{:type => "submit"} Install SSH Key
or
= form_tag [:admin, :revert], :method => :delete, :class => 'revert-form' do
%button{:type => "submit"} Revert to admin
By default, when you impersonate and when you stop impersonating a user you are redirected to the root url.
Configure alternate paths in config/initializers/user_impersonate.rb
, which is created by the generator above.
# config/initializers/user_impersonate.rb
module UserImpersonate
class Engine < Rails::Engine
config.redirect_on_impersonate = "/"
config.redirect_on_revert = "/impersonate"
end
end
By default, it assumes the User model is User
, that you use User.find(id)
to find a user, and aUser.id
to get the related id value.
You can fix this default behavior in config/initializers/user_impersonate.rb
, which is created by the generator above.
# config/initializers/user_impersonate.rb
module UserImpersonate
class Engine < Rails::Engine
config.user_class = "User"
config.user_finder = "find" # User.find
config.user_id_column = "id" # Such that User.find(aUser.id) works
config.user_is_staff_method = "staff?" # current_user.staff?
end
end
FAQs
Unknown package
We found that user_impersonate demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.