Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions lib/phoenix_kit/config/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ defmodule PhoenixKit.Config do
- `:layout_module` - Custom layout configuration
- `:from_email` - Default sender email address for notifications
- `:from_name` - Default sender name for notifications (default: "PhoenixKit")
- `:users_module` - User schema module (default: PhoenixKit.Users.Auth.User)

## Type-Safe Functions

Expand Down Expand Up @@ -61,6 +62,7 @@ defmodule PhoenixKit.Config do
secret_key_base: nil,
oauth_base_url: nil,
# Module-specific settings
users_module: PhoenixKit.Users.Auth.User,
blogging_settings_module: PhoenixKit.Settings
]

Expand Down Expand Up @@ -335,6 +337,17 @@ defmodule PhoenixKit.Config do
end
end

@doc """
Gets the configured users module.
"""
@spec get_users_module() :: module()
def get_users_module do
case get(:users_module) do
{:ok, users_module} when is_atom(users_module) -> users_module
_ -> PhoenixKit.Users.Auth.User
end
end

@doc """
Gets the configured repository module.
"""
Expand Down Expand Up @@ -375,6 +388,20 @@ defmodule PhoenixKit.Config do
end
end

@doc """
Gets configuration from the parent application.

This is useful for accessing parent app mailer, endpoint, or other configurations
that PhoenixKit needs to integrate with.
"""
@spec get_parent_app_config(atom(), any()) :: any()
def get_parent_app_config(key, default \\ nil) do
case get_parent_app() do
nil -> default
app -> Application.get_env(app, key, default)
end
end

@doc """
Gets the parent application name that is using PhoenixKit.

Expand Down
12 changes: 9 additions & 3 deletions lib/phoenix_kit/mailer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,14 @@ defmodule PhoenixKit.Mailer do

# Deliver email with runtime configuration for AWS SES
defp deliver_with_runtime_config(email, mailer, app \\ :phoenix_kit) do
config = Application.get_env(app, mailer, [])
config =
if app == :phoenix_kit do
# Use PhoenixKit config for built-in mailer
PhoenixKit.Config.get(mailer, [])
else
# Use parent app config for parent mailer
PhoenixKit.Config.get_parent_app_config(mailer, [])
end

# If using AWS SES, override with runtime settings from DB
runtime_config =
Expand Down Expand Up @@ -413,8 +420,7 @@ defmodule PhoenixKit.Mailer do

# Detect provider for parent application mailer
defp detect_parent_app_provider(mailer) when is_atom(mailer) do
app = PhoenixKit.Config.get_parent_app()
config = Application.get_env(app, mailer, [])
config = PhoenixKit.Config.get_parent_app_config(mailer, [])
adapter = Keyword.get(config, :adapter)
Utils.adapter_to_provider_name(adapter, "parent_app_mailer")
end
Expand Down
Loading
Loading