Different root routes for authenticated users #358
-
Hello friends! Apologies if this has been asked here before, but I was not able to find a similar question. So please let me know if this is a duplicate. Is there a Rodauth way to have a different root route for authenticated users vs unauthenticated users, similar to the following pattern in Devise?
I've considered creating a class RootController < ApplicationController
def index
if rodauth.logged_in?
redirect_to dashboard_path
else
redirect_to home_path
end
end
end Then using that as the root route as follows: Rails.application.routes.draw do
root to: "root#index"
end But there is likely a more elegant way to do it, possibly with Rodauth settings? I'd appreciate learning about how others have handled this. Thank you! 🌸 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
There aren't built-in constraints that correspond to Devise's constraints -> (r) { !r.env["rodauth"].authenticated? }
root 'pages#home'
end
constraints -> (r) { r.env["rodauth"].authenticated? }
root to: redirect('/dashboard'), as: :authenticated_root
end |
Beta Was this translation helpful? Give feedback.
There aren't built-in constraints that correspond to Devise's
authenticated
&unauthenticated
, but you can write custom ones: