Skip to content

Commit

Permalink
Prepare for Sequel integration
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredcwhite committed Apr 3, 2024
1 parent 18c8c1c commit 2097605
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
23 changes: 16 additions & 7 deletions lib/authtown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
require "authtown/builder"
require "authtown/view_mixin"

# REQUIRES:
# init :"bridgetown-activerecord", sequel_support: :postgres

# ActiveRecord schema:
#
# class CreateUsers < ActiveRecord::Migration[7.0]
Expand All @@ -31,9 +28,17 @@
# end
# end

class Authtown::Current < ActiveSupport::CurrentAttributes
# @!parse def self.user = User.new
attribute :user
Thread.attr_accessor :authtown_state
class Authtown::Current
class << self
def thread_state = Thread.current.authtown_state ||= {}

def user=(new_user)
thread_state[:user] = new_user
end

def user = thread_state[:user]
end
end

# rubocop:disable Metrics/BlockLength
Expand All @@ -42,9 +47,13 @@ class Authtown::Current < ActiveSupport::CurrentAttributes
Bridgetown.initializer :authtown do |
config,
rodauth_config: nil,
account_landing_page: "/account/profile"
account_landing_page: "/account/profile",
user_class_resolver: ->{ User }
|

config.authtown ||= {}
config.authtown.user_class_resolver ||= user_class_resolver

config.only :server do
require "authtown/routes/rodauth"

Expand Down
9 changes: 7 additions & 2 deletions lib/authtown/routes/rodauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ class InitRodauth < Bridgetown::Rack::Routes
rodauth.load_memory

init_current_user
Lifeform::Form.rodauth = rodauth

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

r.on "auth" do
r.rodauth
Expand All @@ -20,7 +24,8 @@ def init_current_user
Authtown::Current.user =
if rodauth.logged_in?
account_id = rodauth.account_from_session[:id]
User.find(account_id)
user_class = bridgetown_site.config.authtown.user_class_resolver.()
user_class[account_id]
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/authtown/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Authtown
VERSION = "0.1.0"
VERSION = "0.2.0"
end

0 comments on commit 2097605

Please sign in to comment.