[英]ActiveAdmin with devise
I have a project using devise_token_auth for authentication. 我有一个使用devise_token_auth进行身份验证的项目。 I have installed Active Admin following this . 我已经安装了主动联系下面这个 。
When I try to access localhost:3000/admin
I get You need to sign in or sign up before continuing.
当我尝试访问localhost:3000/admin
我得到You need to sign in or sign up before continuing.
However, when I comment config.authentication_method = :authenticate_admin_user!
但是,当我评论config.authentication_method = :authenticate_admin_user!
in config/initializers/active_admin.rb
, localhost:3000/admin
opens the dashboard page. 在config/initializers/active_admin.rb
, localhost:3000/admin
打开仪表板页面。
My question is why am I not getting the login page for active admin? 我的问题是为什么我没有获得活动管理员的登录页面?
There are several things that you need to know when working with both ActiveAdmin
(AA) and devise_token_auth
. 同时使用ActiveAdmin
(AA)和devise_token_auth
时,您需要了解几件事。 AA uses: 机管局使用:
Devise
for authentication Devise
认证 :admin
as default namespace :admin
作为默认名称空间 It means that all of your AA resources will have routes under /admin
eg /admin/posts
and they will be authenticated using Devise
; 这意味着您所有的AA资源都将在/admin
下具有路由,例如/admin/posts
并且它们将使用Devise
进行身份验证; not devise_token_auth
. 不是devise_token_auth
。
In order to avail both types of authentication system, you must use two namespaces: one for AA and one for devise_token_auth. 为了使用两种类型的身份验证系统,必须使用两个名称空间:一个用于AA,一个用于devise_token_auth。
A common strategy in this scenario would be to define AA routes before devise_token_auth like so: 在这种情况下,一种常见的策略是在devise_token_auth之前定义AA路由,如下所示:
Rails.application.routes.draw do
# AA routes available at /admin
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
# token auth routes available at /api/v1/auth
namespace :api do
scope :v1 do
mount_devise_token_auth_for 'User', at: 'auth'
end
end
end
Here AA is using :admin_users
and token_auth will use :users
table. 在这里,AA使用:admin_users
,token_auth将使用:users
表。 Don't forget to adapt them to your needs. 不要忘记使它们适应您的需求。
Note : If you ever face trouble with your ApplicationController
while working with AA and devise_token_auth, please refer to this link . 注意 :如果在使用AA和devise_token_auth时遇到ApplicationController
麻烦,请参考此链接 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.