Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
[skip ci] added admin panel authentication guide
Damian Legawiec14733e261b27
diff --git a/docs/developer/admin/authentication.mdx b/docs/developer/admin/authentication.mdxnew file mode 100644index 0000000000..a1a07e4b9e--- /dev/null+++ b/docs/developer/admin/authentication.mdx@@ -0,0 +1,58 @@+---+title: Admin Panel Authentication+sidebarTitle: Authentication+description: How to customize the Spree admin panel authentication+---++By default Spree uses the same model for the admin panel as the storefront. However you can customize it 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:++```ruby+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:++```ruby+include Spree::UserMethods+```++In your `config/initializers/routes.rb` file, you will need define devise routes for the 2nd model:++```ruby+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:++```diff+ 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.++\ No newline at end of filediff --git a/docs/developer/customization/authentication.mdx b/docs/developer/customization/authentication.mdxindex cd6962e29a..11632ec606 100644--- a/docs/developer/customization/authentication.mdx+++ b/docs/developer/customization/authentication.mdx@@ -86,12 +86,4 @@ end## Admin Panel authentication-By default Spree uses the same model for the admin panel as the storefront. However you can customize it to use a different model.--To do this, you need to add the following code to your `config/initializers/spree.rb` file:--```ruby-Spree.admin_user_class = 'AdminUser'-```--This will tell Spree to use the `AdminUser` model for the admin panel. You will need to create this model in your application and ensure that it includes the necessary Spree fields.+Please refer to the [Admin Panel Authentication](/developer/admin/authentication) page for more details.\ No newline at end of filediff --git a/docs/docs.json b/docs/docs.jsonindex 4594220ac0..d74b6f2ceb 100644--- a/docs/docs.json+++ b/docs/docs.json@@ -63,6 +63,7 @@"icon": "gauge","pages": ["developer/admin/admin",+ "developer/admin/authentication","developer/admin/extending-ui","developer/admin/navigation","developer/admin/permissions",diff --git a/docs/images/developer/admin/admin_panel_login.png b/docs/images/developer/admin/admin_panel_login.pngnew file mode 100644index 0000000000..418e1bc000Binary files /dev/null and b/docs/images/developer/admin/admin_panel_login.png differ