lib/timber/integrations/rack/user_context.rb in timber-2.0.1 vs lib/timber/integrations/rack/user_context.rb in timber-2.0.2

- old
+ new

@@ -6,31 +6,44 @@ def initialize(app) @app = app end def call(env) - user = get_user(env) - if user - context = Contexts::User.new( - id: user_id(user), - name: user_name(user), - email: user_email(user) - ) + user_hash = get_user_hash(env) + if user_hash + context = Contexts::User.new(user_hash) CurrentContext.with(context) do @app.call(env) end else @app.call(env) end end private - def get_user(env) + def get_user_hash(env) if env['warden'] - env['warden'].user + get_user_hash_from_object(env['warden'].user) + elsif env['omniauth.auth'] + auth_hash = env['omniauth.auth'] + info = auth_hash['info'] + + { + id: auth_hash['uid'], + name: info['name'], + email: info['email'] + } else nil end + end + + def get_user_hash_from_object(user) + { + id: user_id(user), + name: user_name(user), + email: user_email(user) + } end def user_id(user) user.respond_to?(:id) ? user.id : nil end \ No newline at end of file