Skip to content

Conversation

@grdsdev
Copy link
Contributor

@grdsdev grdsdev commented Nov 3, 2025

Summary

Replaces the EmitLocalSessionAsInitialSession trait with a runtime configuration flag to resolve compatibility issues with Xcode projects and align with Apple's trait guidelines.

Problem

The current trait-based approach has several issues:

  1. Xcode incompatibility: iOS projects cannot enable traits (no Package.swift, no UI/CLI support)
  2. Violates Apple's guidelines: Traits should be strictly additive and not alter API behavior
  3. Limited discoverability: Users in Xcode won't know this option exists

Solution

Implemented a runtime configuration flag emitLocalSessionAsInitialSession: Bool in AuthClient.Configuration:

  • Defaults to false for backward compatibility
  • Can be set at initialization without recompilation
  • Works in all project types (Xcode, SPM)
  • Discoverable through autocomplete and documentation

Changes

  • ✅ Added emitLocalSessionAsInitialSession: Bool property to AuthClient.Configuration
  • ✅ Replaced conditional compilation (#if EmitLocalSessionAsInitialSession) with runtime checks
  • ✅ Updated deprecation warning to reference the new configuration option
  • ✅ Added separate tests for both behaviors (old and new)
  • ✅ Removed EmitLocalSessionAsInitialSession trait from Package@swift-6.1.swift
  • ✅ All 78 AuthClientTests passing

Migration

Users who want the new behavior can now set:

let client = AuthClient(
  url: url,
  headers: headers,
  localStorage: storage,
  emitLocalSessionAsInitialSession: true  // Opt-in to new behavior
)

Or using configuration:

let config = AuthClient.Configuration(
  url: url,
  // ... other parameters
  emitLocalSessionAsInitialSession: true
)
let client = AuthClient(configuration: config)

Test Plan

  • Build succeeds (swift build)
  • All AuthClientTests pass (78/78)
  • Tests cover both old behavior (default) and new behavior (with flag enabled)
  • No breaking changes for existing users

Breaking Changes

None. The default behavior remains unchanged (false). This will change to true in the next major release (v3.0.0).

🤖 Generated with Claude Code

grdsdev and others added 2 commits November 3, 2025 07:07
Replaces the EmitLocalSessionAsInitialSession trait with a runtime configuration flag to resolve compatibility issues with Xcode projects and align with Apple's trait guidelines.

## Changes

- Added `emitLocalSessionAsInitialSession: Bool` property to `AuthClient.Configuration`
  - Defaults to `false` for backward compatibility
  - Will change to `true` in next major release
- Replaced conditional compilation (`#if EmitLocalSessionAsInitialSession`) with runtime checks
- Updated deprecation warning to reference the new configuration option
- Added tests for both behaviors (old and new)
- Removed `EmitLocalSessionAsInitialSession` trait from Package@swift-6.1.swift

## Benefits

- Works in all project types (Xcode, SPM, CocoaPods)
- No recompilation required to change behavior
- Better discoverability through autocomplete and docs
- Complies with Apple's trait guidelines (traits must be strictly additive)

## Migration

Users who want the new behavior can now set:
```swift
AuthClient(
  // ... other config
  emitLocalSessionAsInitialSession: true
)
```

Resolves compatibility issues where Xcode projects cannot enable package traits.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Adds support for the emitLocalSessionAsInitialSession flag in SupabaseClientOptions.AuthOptions so users can configure this behavior when creating a SupabaseClient.

- Added emitLocalSessionAsInitialSession property to SupabaseClientOptions.AuthOptions
- Updated both initializers to include the new parameter
- Pass the flag through to AuthClient initialization in SupabaseClient

This ensures users can configure the flag whether they create an AuthClient directly or use SupabaseClient.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR replaces the Swift 6.1 experimental package trait EmitLocalSessionAsInitialSession with a runtime configuration option emitLocalSessionAsInitialSession. This change provides a more accessible way for users to opt into the new behavior where the locally stored session is emitted immediately as the initial session, rather than waiting for a refresh attempt first.

Key changes:

  • Removed the Package@swift-6.1.swift file that used the experimental trait feature
  • Added emitLocalSessionAsInitialSession configuration parameter throughout the Auth client initialization chain
  • Replaced compile-time #if EmitLocalSessionAsInitialSession conditionals with runtime if configuration.emitLocalSessionAsInitialSession checks
  • Updated tests to use the new runtime configuration instead of conditional compilation

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Package@swift-6.1.swift Removed file that defined the experimental package trait
Sources/Auth/AuthClient.swift Replaced conditional compilation directives with runtime checks based on the new configuration property
Sources/Auth/AuthClientConfiguration.swift Added emitLocalSessionAsInitialSession configuration property with documentation
Sources/Supabase/Types.swift Added emitLocalSessionAsInitialSession to auth options with default value for backward compatibility
Sources/Supabase/SupabaseClient.swift Threaded through the new configuration parameter to AuthClient initialization
Tests/AuthTests/AuthClientTests.swift Replaced conditional test expectations with separate test variants for both behavior modes

@vojtabohm
Copy link

Amazing! Thank you for looking into it so SWIFTly :)

@vojtabohm
Copy link

Seems to be working as intended. Going to production with it. Thanks!

@grdsdev grdsdev merged commit e0bdfe8 into main Nov 3, 2025
28 checks passed
@grdsdev grdsdev deleted the fix/replace-trait-with-runtime-config branch November 3, 2025 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants