Stopping users from going back to original root_path after login with Devise?

The authenticated user root path works perfectly. What I’m trying to do is stop the user from returning back to the root ‘welcome#index’ after login?

authenticated :user do
  root 'hub#index', as: :authenticated_root
end

# How can I stop users from going back to root 'welcome#index' after they've logged in.

Hey David,

Devise has an additional constraint named unauthenticated which you can use to restrict access to routes for a logged in user.

For example,

authenticated :user do

root ‘hub#index’, as: :authenticated_root

end

unauthenticated :user do

place routes for unauthenticated users only here

resources :welcomes

end

What you’ll find is that now if the user tries to navigate to the /welcomes path while logged in, the route will be undefined.

Documentation is here:

http://www.rubydoc.info/github/plataformatec/devise/master/ActionDispatch%2FRouting%2FMapper%3Aunauthenticated

Hope that helps!