Using Multiple User Classes
Last updated
Last updated
This gem supports the use of multiple user models. One possible use case is to authenticate visitors using a model called User
, and to authenticate administrators with a model called Admin
. Take the following steps to add another authentication model to your app:
Run the install generator for the new model.
This will create the Admin
model and define the model's authentication routes with the base path /admin_auth
.
Define the routes to be used by the Admin
user within a .
Example:
Configure any Admin
restricted controllers. Controllers will now have access to the methods :
before_action :authenticate_admin!
current_admin
admin_signed_in?
It is also possible to control access to multiple user types at the same time using groups. The following example shows how to limit controller access to both User
and Admin
users.
In the above example, the following methods will be available (in addition to current_user
, current_admin
, etc.):
before_action: :authenticate_member!
current_member
member_signed_in?