I have two models User and Admin(with RailsAdmin) that use Devise. I sign in as user and then sign in as admin. But the result of signing out from one of that models is signing out of two models at the same time. How can I fix it? Please, help :)
Devise separate sign out for two different models
Asked Answered
The problem was in one string in config/initializers/devise.rb:
Default:
# Configure sign_out behavior.
# Sign_out action can be scoped (i.e. /users/sign_out affects only :user scope).
# The default is true, which means any logout action will sign out all active scopes.
# config.sign_out_all_scopes = trueNeed:
config.sign_out_all_scopes = false
While the OP is satisfied with the accepted answer, the technically answer to the original question is this one. –
Tybi
You should accept this as a solution, or this is not possible? –
Dribble
@IvailoBardarov, thanks for the reminder. I received -2 to rating for reaccepting, but it's not a big issue :) –
Vullo
The scope of Devise is the entire application -- you sign in to the site, not a model. Perhaps you want to add the distinction of roles - a user may have one or more roles that allow them certain privileges. Devise just gets you an authenticated user. Consider a gem such as CanCan which provides support for "role based authorization".
Thank you for your reply. You really made things about the scope of Devise more clear to me. Initially I have wanted use two separate models - Creating an admin model, but now I understand that it wasn't the best choice. Nonetheless, have I any chances to stay my way or it will be better to use roles with only user model? –
Vullo
Both: authentication (Devise) and authorization (CanCan or other role approach) are different. –
Human
Devise can be scoped on a per model basis: github.com/plataformatec/devise#configuring-multiple-models (This may not have been true at the time this question was first answered) –
Ecclesiasticism
© 2022 - 2024 — McMap. All rights reserved.