Skip to content

Fix OAuth buttons generating incorrect URLs with locale prefix - #198

Merged
ddon merged 3 commits into
BeamLabEU:devfrom
timujinne:dev
Nov 25, 2025
Merged

Fix OAuth buttons generating incorrect URLs with locale prefix#198
ddon merged 3 commits into
BeamLabEU:devfrom
timujinne:dev

Conversation

@timujinne

Copy link
Copy Markdown
Contributor

Summary

  • Fixed OAuth authentication buttons (Google, Apple, GitHub, Facebook) generating incorrect URLs
  • URLs were incorrectly including locale prefix (e.g., /phoenix_kit/en/users/auth/google)
  • This caused blog catch-all routes to intercept OAuth requests, returning 404

Changes

  • Added locale: :none option to all OAuth button links in oauth_buttons.ex
  • OAuth routes are non-localized by design, so links should not include locale prefix

Test Plan

  • Verified OAuth buttons now generate correct URLs without locale prefix
  • Verified Google OAuth authentication flow works correctly
  • Pre-commit checks passed (compilation, credo, dialyzer)

OAuth routes are defined without locale prefix, but Routes.path() was
adding locale by default, causing URLs like /phoenix_kit/en/users/auth/google
instead of /phoenix_kit/users/auth/google. This made blog catch-all routes
intercept OAuth requests, returning 404.

Added locale: :none option to all OAuth button links.
…onditions

When OAuth settings are updated in the admin panel and providers are
reconfigured, the cache may not be invalidated yet. This caused OAuth
configuration to use stale credentials from cache.

Added get_oauth_credentials_direct/1, has_oauth_credentials_direct?/1,
and get_settings_direct/1 functions that bypass cache for security-critical
operations. OAuthConfig now uses these direct reads when configuring
providers after settings updates.
@timujinne

Copy link
Copy Markdown
Contributor Author

Additional Commit: Add direct database reads for OAuth credentials

This commit fixes a race condition where OAuth configuration used stale cached credentials after settings update.

Changes

Settings Module (lib/phoenix_kit/settings/settings.ex):

  • Added get_oauth_credentials_direct/1 - reads credentials directly from DB
  • Added has_oauth_credentials_direct?/1 - validates credentials directly from DB
  • Added get_settings_direct/1 - generic direct DB read for multiple keys

OAuth Config Module (lib/phoenix_kit/users/oauth_config.ex):

  • configure_providers/0 now uses direct DB reads for all provider configurations
  • build_provider_list/0 uses direct credential checks
  • validate_credentials/1 uses direct DB reads

Why this is needed

When OAuth settings are updated in the admin panel and providers are reconfigured, the cache may not be invalidated yet. This caused OAuth configuration to read stale credentials from cache, making the new settings appear to not work.

Cache is still used for non-critical operations (UI display, availability checks in templates).

Extended direct database reads for OAuth credentials to all remaining
modules that check credentials availability:

- OAuthAvailability.available_providers/0 now uses has_oauth_credentials_direct?/1
- OAuthConfigLoader now uses has_oauth_credentials_direct?/1 for provider checks
- warm_critical_cache/0 no longer caches OAuth credentials (they use direct reads)

This ensures consistent behavior across all OAuth-related code paths and
prevents race conditions when credentials are updated through admin UI.
@timujinne

Copy link
Copy Markdown
Contributor Author

Additional Commit: Use direct DB reads for OAuth credentials throughout the codebase

Extended direct database reads for OAuth credentials to all remaining modules:

Changes

OAuthAvailability (lib/phoenix_kit/users/oauth_availability.ex):

  • available_providers/0 now uses has_oauth_credentials_direct?/1 for all provider checks

OAuthConfigLoader (lib/phoenix_kit/workers/oauth_config_loader.ex):

  • Provider availability checks now use has_oauth_credentials_direct?/1

Settings (lib/phoenix_kit/settings/settings.ex):

  • warm_critical_cache/0 no longer caches OAuth credentials
  • Credentials use direct DB reads, so caching them would be counterproductive

This ensures consistent behavior across all OAuth-related code paths.

@ddon
ddon merged commit 2a1564e into BeamLabEU:dev Nov 25, 2025
6 checks passed
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