Muhammad Faisal Iqbal Muhammad Faisal Iqbal - 6 months ago 29
Ruby Question

Conditional Route on sign_out using Devise with Rails

I am working on an app in which there is a model User with roles member and Admin.

As per requirement, I have to made two separate login pages for Admin and Member.

with

http://localhost:3000/admin/admin_login


it goes to admin login page and with

http://localhost:3000/users/sign_in


it goes to member login page.
Just after login I route them according to their roles to Admin panel or simple website for members.

But at time of logout both goes to
http://localhost:3000


but I want admin to go to
http://localhost:3000/admin/admin_login
,
while
http://localhost:3000
is fine for member's logout.

Is there a way to see User's Role at time of Sign_out and route them accordingly.

Answer

To avoid sign_out to clear all sessions you can use

config.sign_out_all_scopes = false

in devise.rb than it will not clear all sessions.

Than at time of sign_in create as session like

session["Role"] = "Admin" etc

and in logout check the session and route accordingly