Skip to content

Conversation

@mamhoff
Copy link
Contributor

@mamhoff mamhoff commented Oct 11, 2025

What is this pull request for?

This converts the auth_accessors.rb module, which is purely configuration, to a configuration object.

All methods are still there, but deprecated, and a few accessors stay in lib/alchemy.rb as shortcuts.

Notable changes (remove if none)

We can now configure Alchemy's auth system entirely outside of a config.to_prepare block.

Checklist

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have added tests to cover this change

@mamhoff mamhoff requested a review from a team as a code owner October 11, 2025 09:22
@mamhoff mamhoff force-pushed the auth-configuration branch 3 times, most recently from d5c9603 to 954e985 Compare October 11, 2025 09:56
@codecov
Copy link

codecov bot commented Oct 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.27%. Comparing base (2b0b699) to head (1b0afb4).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3418      +/-   ##
==========================================
+ Coverage   97.25%   97.27%   +0.02%     
==========================================
  Files         291      291              
  Lines        7682     7706      +24     
==========================================
+ Hits         7471     7496      +25     
+ Misses        211      210       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tvdeyen tvdeyen force-pushed the auth-configuration branch from 954e985 to 8645785 Compare October 11, 2025 11:42
@mamhoff mamhoff force-pushed the auth-configuration branch 2 times, most recently from c6d73b9 to 74d6166 Compare October 15, 2025 12:03
@mamhoff
Copy link
Contributor Author

mamhoff commented Oct 15, 2025

Rebased on #3424 in order to get the raw_user_class reader.

@mamhoff mamhoff force-pushed the auth-configuration branch from 74d6166 to a85e1b4 Compare October 15, 2025 12:10

alias_method :get, :send
alias_method :[], :get
alias_method :configure, :tap
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s.m.a.r.t.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the example in the commit message is weird though.

README.md Outdated
Alchemy.unauthorized_path = '/some/public/page' # Defaults to '/'
Alchemy.configure do |config|
config.auth.configure do |auth|
auth.user_class_name = 'YourUserClass' # Defaults to 'User'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auth.user_class_name     = 'YourUserClass'          # Defaults to nil

#
# Alchemy has some defaults for user model name and login logout path names:
#
# +Alchemy.config.auth.user_class_name+ defaults to +'User'+
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# +Alchemy.config.auth.user_class_name+ defaults to +nil+

Or add the `alchemy-devise` gem to your Gemfile:
bundle add alchemy-devise
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe find a better way for this warning

@mamhoff mamhoff force-pushed the auth-configuration branch 2 times, most recently from e1adfda to 43681c3 Compare October 16, 2025 12:41
@github-actions
Copy link

This pull request has not seen any activiy in a long time.
Probably because of missing tests or a necessary rebase.
This PR will be closed in 7 days if no further activity happens.

@github-actions github-actions bot added the Stale label Dec 16, 2025
@tvdeyen tvdeyen added this to the 8.1 milestone Dec 23, 2025
@tvdeyen
Copy link
Member

tvdeyen commented Dec 23, 2025

@mamhoff this needs a rebase and conflict resolution.

@github-actions github-actions bot removed the Stale label Dec 24, 2025
@mamhoff mamhoff force-pushed the auth-configuration branch 2 times, most recently from d13264a to 20a4bdb Compare December 28, 2025 17:20
Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for rebasing. I think we should get rid of the extra auth class. It is unnecessary imo.


alias_method :get, :send
alias_method :[], :get
alias_method :configure, :tap
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the example in the commit message is weird though.


module Alchemy
module Configurations
class Auth < Alchemy::Configuration
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should add another configuration class just for auth. The methods have conflict free names and it only makes it harder to read and use. Alchemy.config.user_class is perfect. Alchemy.config.auth.user_class is to verbose and does not provide anything useful.

@mamhoff mamhoff force-pushed the auth-configuration branch 3 times, most recently from a4034bf to e80ebb2 Compare December 29, 2025 10:42
If `Alchemy.user_class` is `nil`, which it is in case of an invalid
configuration, it's not a class, and we can't use the `<` operator.
Let's use duck typing instead.
This allows us to do

```
Alchemy.configure do |config|
  config.user_class = "Spree::User"
end
```
Creates a configuration object for authentication that can be
initialized outside of a `config.to_prepare` block.

Configuration is now in `Alchemy.config.auth`.
@mamhoff mamhoff force-pushed the auth-configuration branch from e80ebb2 to 1b0afb4 Compare January 2, 2026 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants