feat(auth-next,wallet): add default auth with auto-detection #2792
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Implement default authentication for
@imtbl/wallet,@imtbl/auth-next-client, and@imtbl/auth-next-serverpackages to provide zero-config setup for developers.This PR adds:
auth-next-serverwith auto-detectionauth-next-clientwith optional configChanges
1. Wallet Package Tests (
test(wallet))2. Auth-Next-Server (
feat(auth-next-server))createDefaultAuthConfig()with optional configurationclientIdbased on environment (sandbox vs production)redirectUrifromwindow.location.origin + '/callback'audience,scope, andauthenticationDomainDEFAULT_PRODUCTION_CLIENT_ID: Public Immutable production client IDDEFAULT_SANDBOX_CLIENT_ID: Public Immutable sandbox client IDDEFAULT_REDIRECT_URI_PATH: Default callback pathisSandboxEnvironment(): Detects sandbox vs productionderiveDefaultClientId(): Auto-detects clientIdderiveDefaultRedirectUri(): Auto-derives redirectUri3. Auth-Next-Client (
feat(auth-next-client))useLoginanduseLogoutnow accept optional configclientId,redirectUri,popupRedirectUri,logoutRedirectUriscope,audience,authenticationDomaincreateDefaultLoginConfig(): Creates complete LoginConfig with defaultscreateDefaultLogoutConfig(): Creates complete LogoutConfig with defaultsUsage Examples
Before (Required Configuration)
Server (
lib/auth.ts):Client (
components/LoginButton.tsx):After (Zero Configuration)
Server (
lib/auth.ts):Client (
components/LoginButton.tsx):With Custom Configuration (Optional)
You can still override any field as needed:
Auto-Detection Logic
ClientId Detection
window.location.hostnamefor 'sandbox' or 'localhost'DEFAULT_SANDBOX_CLIENT_IDDEFAULT_PRODUCTION_CLIENT_IDRedirectUri Derivation
/callback)window.location.origin + '/callback'Testing
Breaking Changes
None. This is a fully backward-compatible addition:
createAuthConfig()still works as beforeuseLogin()anduseLogout()usage still worksRelated Work
Test Plan
Notes
windowis unavailable)Made with Cursor