> ## Documentation Index
> Fetch the complete documentation index at: https://spreecommerce.org/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Admin Panel Authentication

> How to customize the Spree admin panel authentication

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:

```ruby theme={"theme":"night-owl"}
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 theme={"theme":"night-owl"}
include Spree::UserMethods
```

In your `config/initializers/routes.rb` file, you will need define devise routes for the 2nd model:

```ruby theme={"theme":"night-owl"}
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 theme={"theme":"night-owl"}
     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.

<img src="https://mintcdn.com/spreecommerce/II6sKnqAuUp3_6IP/images/developer/admin/admin_panel_login.png?fit=max&auto=format&n=II6sKnqAuUp3_6IP&q=85&s=a246f31187ca79e8e76e79df3e4a7f93" alt="Admin panel login page" width="3248" height="2112" data-path="images/developer/admin/admin_panel_login.png" />
