Sign Out Specific User with Devise in Rails

how to force another user to sign out with devise?

Devise allows you to sign in and sign out users forcefully.

Sign in a user that already was authenticated.

sign_in :user, @user                      # sign_in(scope, resource)
sign_in @user

Similarly you can sign out the user as

sign_out :user     # sign_out(scope)
sign_out @user # sign_out(resource)

For more information please refer to this link

How can I make specific user(not current_user) sign out on rails-devise website?

One way you could do this is create a new attribute in the User table, call it force_sign_out.

def kick_admin
user = User.find params[:user_id]
user.update_attributes(admin: false, force_sign_out: true)
end

And have a before action in ApplicatonController so that if the user attempts any activity he's signed out

class ApplicationController < ActionController::Base

before_action :check_if_force_sign_out

def check_if_force_sign_out
return unless current_user.force_sign_out
current_user.update_attributes(force_sign_out: false) # reset for non-admin log in
sign_out
redirect_to root_path
end

end

Logout users with devise gem rails

You can use the sign_out method in the controller action by passing in the user object:

# Make sure only admins can do this
def sign_out_user
@user = User.find(params[:id])
sign_out @user
end

More info here:

http://rubydoc.info/github/plataformatec/devise/master/Devise/TestHelpers%3asign_out



Related Topics



Leave a reply



Submit