Skip to content

Transition from Devise

Ken Decanio edited this page Aug 6, 2025 · 7 revisions

in routes.rb

One often sees authentication dependent root paths as such:

  authenticated :user do
    root to: "pages#home", as: :authenticated_root
  end
  unauthenticated do
    root to: "pages#welcome"
  end

This, does not work with Rodauth-rails.

The following is not pretty but:

  constraints -> (r) { !r.env["rodauth"].authenticated? } do
    root 'pages#welcome'
  end

  constraints -> (r) { r.env["rodauth"].authenticated? } do
    root to: 'pages#home', as: :authenticated_root
  end

ActiveRecord

The first rule of Rodauth-Rails is Rodauth uses Sequel and does NOT use ActiveRecord so it will not ever do anything with an object especially an ActiveRecord object.

ActiveRecord Callbacks

First rule tells us Rodauth uses Sequel to interact with the database so ActiveRecord callbacks are never called. Look in 'app/misc/rodauth_main.rb' for 'after_create_account'. This is where you can put anything you would normally put in an after_create callback. Even if you are using User as your model, the access you have is to 'account_id' which will allow for User.find(account_id). Your callbacks cannot be private to be able to call them here.

    after_create_account do
      # puts "**************  Rodauth after_create_account USER #{account_id}   *****************"
      u = User.find account_id
      u.callback_1
      u.callback_2
    end

Testing

These will create and verify an account

RodauthApp.rodauth.create_account( login: "[email protected]", password: "password1234!" )
RodauthApp.rodauth.verify_account( account_login: "[email protected]" )

This will not provide any object for you to use. For that

user = User.last

Documentation

RodauthApp.rodauth gets you to Rodauth in general and to 'internal requests' in particular. Internal Requests are documented here. Above you see calls to 'create_account' and 'verify_account'. They are both documented there.

Clone this wiki locally