Skip to content

Fix critical OAuth and IPv6 handling issues - #134

Merged
ddon merged 2 commits into
BeamLabEU:devfrom
timujinne:dev
Oct 26, 2025
Merged

Fix critical OAuth and IPv6 handling issues#134
ddon merged 2 commits into
BeamLabEU:devfrom
timujinne:dev

Conversation

@timujinne

Copy link
Copy Markdown
Contributor

Summary

  • Fixed missing halt(conn) in OAuth request handler causing 500 errors
  • Centralized IPv6/IPv4 IP extraction to prevent Protocol.UndefinedError
  • Verified OAuth config loads at startup via integration macro

Changes

Problem #1: OAuth halt() missing (CRITICAL)

  • Added halt(conn) to handle_oauth_request() in lib/phoenix_kit_web/users/oauth.ex:106
  • Prevents Phoenix from attempting to render non-existent view after Ueberauth processing

Problem #2: IPv6 Protocol.UndefinedError (HIGH PRIORITY)

  • Created lib/phoenix_kit/utils/ip_address.ex with proper pattern matching for IPv4 and IPv6
  • Removed duplicate extract_ip_address() implementations from 7 files
  • Updated all call sites to use IpAddress.extract_from_socket() or IpAddress.extract_from_conn()

Problem #3: OAuth config not loading at startup

  • Verified existing implementation in integration.ex:442-463
  • phoenix_kit_routes() macro properly initializes OAuth configuration

Test Plan

  • All 17 unit tests passing (4 doctests + 13 tests)
  • Format, credo, and dialyzer checks passed
  • Code quality: no issues found
  • All 7 modified files verified using new IpAddress module
  • OAuth halt() implementation confirmed
  • Regression testing: no new failures

## Problem #1: OAuth halt() missing (CRITICAL)
Fixed missing halt(conn) call in handle_oauth_request() that caused 500 errors
when users clicked OAuth sign-in buttons. Phoenix would attempt to render a
non-existent view template after Ueberauth processed the request.
Modified: lib/phoenix_kit_web/users/oauth.ex:105
## Problem #2: IPv6 Protocol.UndefinedError (HIGH PRIORITY)
Created centralized PhoenixKit.Utils.IpAddress module to prevent
Protocol.UndefinedError when extracting IPv6 addresses.
Root cause: Six files had duplicate extract_ip_address() functions calling
to_string(address) on IPv6 tuples without proper guard clauses. This caused:
Protocol.UndefinedError: String.Chars not implemented for IPv6 tuples
Solution:
- Created lib/phoenix_kit/utils/ip_address.ex with proper pattern matching:
* IPv4: {a, b, c, d} pattern with is_integer guards
* IPv6: {a, b, c, d, e, f, g, h} pattern with is_integer guards
* Invalid/nil: returns "unknown"
- Removed duplicate implementations from 7 files:
* lib/phoenix_kit_web/live/dashboard.ex
* lib/phoenix_kit_web/users/login.ex
* lib/phoenix_kit_web/users/registration.ex
* lib/phoenix_kit_web/users/magic_link.ex
* lib/phoenix_kit_web/live/users/live_sessions.ex
* lib/phoenix_kit/utils/geolocation.ex
* lib/phoenix_kit_web/users/oauth.ex
- Updated all call sites to use IpAddress.extract_from_socket() or
IpAddress.extract_from_conn() for consistency
## Problem #3: OAuth config not loading at startup
Already fixed in current version (integration.ex:442-463).
phoenix_kit_routes() macro spawns task that calls OAuthConfig.configure_providers()
with 100ms delay to ensure database is ready.
## Code Quality
- Fixed all Credo compilation warnings (alias ordering, number formatting)
- Comprehensive unit tests added (17 test cases covering IPv4, IPv6, edge cases)
- All tests passing
- No compilation errors or warnings
## Added to 1.4.5 Changelog
- OAuth halt() missing in request handler fix
- IPv6 Protocol.UndefinedError resolution with centralized IpAddress module
- Google OAuth credentials auto-reload after save
- OAuth error message improvements (user-friendly field names)
- AWS credentials verification simplification
- Settings error diagnostics improvements
- AWS SES v2 infrastructure fixes
## Details
- Date updated: 2025-10-26
- 5 commits included in release
- All critical OAuth and IPv6 issues documented
- AWS infrastructure improvements documented
- Full upgrade notes and technical details included
@ddon
ddon merged commit 825c3c6 into BeamLabEU:devOct 26, 2025
Sign up for freeto 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

@timujinne@ddon