Sha256: 267f053f49df50df73611abaeeacfe2265a30f7c9d6a2a400ba741e2ef3ad71e

Contents?: true

Size: 781 Bytes

Versions: 3

Compression:

Stored size: 781 Bytes

Contents

# frozen_string_literal: true

module Authtown
  module Routes
    class InitRodauth < Bridgetown::Rack::Routes
      priority :highest

      route do |r|
        rodauth.load_memory

        init_current_user

        # @example hook usage:
        #   hook :authtown, :initialized do |rodauth|
        #     Lifeform::Form.rodauth = rodauth
        #   end
        Bridgetown::Hooks.trigger(:authtown, :initialized, rodauth)

        r.on "auth" do
          r.rodauth
        end
      end

      def init_current_user
        Authtown::Current.user =
          if rodauth.logged_in?
            # load existing account hash into Model:
            bridgetown_site.config.authtown.user_class_resolver.().(rodauth.account_from_session)
          end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
authtown-0.5.0 lib/authtown/routes/rodauth.rb
authtown-0.4.0 lib/authtown/routes/rodauth.rb
authtown-0.3.0 lib/authtown/routes/rodauth.rb