@@ -2516,6 +2516,86 @@ describe('Clerk singleton', () => {
25162516 } ) ;
25172517 } ) ;
25182518 } ) ;
2519+
2520+ describe ( 'auto-detection for eligible hosts' , ( ) => {
2521+ const originalLocation = window . location ;
2522+
2523+ afterEach ( ( ) => {
2524+ Object . defineProperty ( window , 'location' , {
2525+ value : originalLocation ,
2526+ writable : true ,
2527+ } ) ;
2528+ } ) ;
2529+
2530+ test ( 'auto-derives proxyUrl for production instances on eligible hosts' , ( ) => {
2531+ Object . defineProperty ( window , 'location' , {
2532+ value : {
2533+ ...originalLocation ,
2534+ hostname : 'myapp-abc123.vercel.app' ,
2535+ origin : 'https://myapp-abc123.vercel.app' ,
2536+ href : 'https://myapp-abc123.vercel.app/dashboard' ,
2537+ } ,
2538+ writable : true ,
2539+ } ) ;
2540+
2541+ const sut = new Clerk ( productionPublishableKey ) ;
2542+ expect ( sut . proxyUrl ) . toBe ( 'https://myapp-abc123.vercel.app/__clerk' ) ;
2543+ } ) ;
2544+
2545+ test ( 'does NOT auto-derive proxyUrl for development instances on eligible hosts' , ( ) => {
2546+ Object . defineProperty ( window , 'location' , {
2547+ value : {
2548+ ...originalLocation ,
2549+ hostname : 'myapp-abc123.vercel.app' ,
2550+ origin : 'https://myapp-abc123.vercel.app' ,
2551+ href : 'https://myapp-abc123.vercel.app/dashboard' ,
2552+ } ,
2553+ writable : true ,
2554+ } ) ;
2555+
2556+ const sut = new Clerk ( developmentPublishableKey ) ;
2557+ expect ( sut . proxyUrl ) . toBe ( '' ) ;
2558+ } ) ;
2559+
2560+ test ( 'does NOT auto-derive proxyUrl for ineligible domains' , ( ) => {
2561+ const sut = new Clerk ( productionPublishableKey ) ;
2562+ expect ( sut . proxyUrl ) . toBe ( '' ) ;
2563+ } ) ;
2564+
2565+ test ( 'explicit proxyUrl takes precedence over auto-detection' , ( ) => {
2566+ Object . defineProperty ( window , 'location' , {
2567+ value : {
2568+ ...originalLocation ,
2569+ hostname : 'myapp-abc123.vercel.app' ,
2570+ origin : 'https://myapp-abc123.vercel.app' ,
2571+ href : 'https://myapp-abc123.vercel.app/dashboard' ,
2572+ } ,
2573+ writable : true ,
2574+ } ) ;
2575+
2576+ const sut = new Clerk ( productionPublishableKey , {
2577+ proxyUrl : 'https://custom-proxy.example.com/__clerk' ,
2578+ } ) ;
2579+ expect ( sut . proxyUrl ) . toBe ( 'https://custom-proxy.example.com/__clerk' ) ;
2580+ } ) ;
2581+
2582+ test ( 'explicit domain skips auto-detection' , ( ) => {
2583+ Object . defineProperty ( window , 'location' , {
2584+ value : {
2585+ ...originalLocation ,
2586+ hostname : 'myapp-abc123.vercel.app' ,
2587+ origin : 'https://myapp-abc123.vercel.app' ,
2588+ href : 'https://myapp-abc123.vercel.app/dashboard' ,
2589+ } ,
2590+ writable : true ,
2591+ } ) ;
2592+
2593+ const sut = new Clerk ( productionPublishableKey , {
2594+ domain : 'clerk.myapp.com' ,
2595+ } ) ;
2596+ expect ( sut . proxyUrl ) . toBe ( '' ) ;
2597+ } ) ;
2598+ } ) ;
25192599 } ) ;
25202600
25212601 describe ( 'buildUrlWithAuth' , ( ) => {
0 commit comments