docs/developer/admin/authentication.mdx
Spree allows you to use a different model for the admin panel than the storefront (that's the default since Spree 5.2). Here you can find how to customize the admin panel authentication to use a different model.
Let's assume you have an existing AdminUser model in your application and you're using Devise for authentication.
In config/initializers/spree.rb file, add the following line:
Spree.admin_user_class = 'AdminUser'
This will tell Spree to use your AdminUser model for the admin panel. You will also need to add the following line in that model file:
include Spree::UserMethods
In your config/initializers/routes.rb file, you will need define devise routes for the 2nd model:
Spree::Core::Engine.routes.prepend_routes do
# Admin authentication
devise_for(
Spree.admin_user_class.model_name.singular_route_key,
class_name: Spree.admin_user_class.to_s,
controllers: {
sessions: 'spree/admin/user_sessions',
passwords: 'spree/admin/user_passwords'
},
skip: :registrations,
path: :admin_user,
router_name: :spree
)
end
And now in your lib/spree/authentication_helpers.rb file, please replace the following lines:
def spree_admin_login_path(opts = {})
- spree_login_path(opts)
+ new_admin_user_session_path(opts)
end
def spree_admin_logout_path(opts = {})
- spree_logout_path(opts)
+ destroy_admin_user_session_path(opts)
end
Now when attempting to access the admin panel, you will be redirected to the dedicated admin panel login page.