How to force re-login with Devise and Warden without logging out the user?

68 Views Asked by At

Need to add a feature so that a user is required to log in again. However, they cannot be signed out.

I was able to create a new sign in page that does not redirect if they are already logged in.

However, the problem with this approach is that I need to handle failures. Ideally, if the login fails then they this new sign in page would be re-rendered (or the user could be redirected to it).

1

There are 1 best solutions below

0
markets On

I think you can try to use something like this: https://github.com/markets/sudo_rails. With this gem, you can require your users to enter again the password for some sensible actions by using the sudo macro in your controller:

class SettingsController < ApplicationController
  sudo only: :sensible_settings
end

enter image description here

It also comes with Devise integration and UI customization.