PhoenixKit.Workers.OAuthConfigLoader (phoenix_kit v1.5.1)

View Source

GenServer worker that ensures OAuth configuration is loaded from database before any OAuth requests are processed.

This worker runs synchronously during application startup to prevent timing issues where Ueberauth plug is initialized before OAuth providers are configured.

Startup Sequence

  1. Worker starts as first child in PhoenixKit.Supervisor
  2. Waits for Settings cache to be ready (with timeout)
  3. Loads OAuth configuration from database
  4. Configures Ueberauth with available providers
  5. Returns :ok when complete

Why This Is Needed

Parent applications typically start services in this order:

  • Repo (database ready)
  • PubSub
  • Parent Endpoint (router compiles, Ueberauth.init() runs)
  • PhoenixKit.Supervisor (OAuth config should load here)

If PhoenixKit.Supervisor starts AFTER Parent Endpoint, the OAuth configuration arrives too late and Ueberauth fails with MatchError.

This worker ensures OAuth configuration is available as early as possible during PhoenixKit.Supervisor initialization.

Summary

Functions

Returns a specification to start this module under a supervisor.

Gets the current status of OAuth configuration.

Attempts to reload OAuth configuration.

Starts the OAuth configuration loader.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_status()

Gets the current status of OAuth configuration.

Returns:

  • {:ok, :loaded} - Configuration successfully loaded
  • {:ok, :not_loaded, reason} - Configuration not loaded with reason
  • {:error, :not_running} - OAuthConfigLoader is not running

reload_config()

Attempts to reload OAuth configuration.

This can be called to retry loading configuration if it failed during startup.

start_link(opts)

Starts the OAuth configuration loader.

Blocks until OAuth configuration is successfully loaded or max retries exceeded.