File tree Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -1334,6 +1334,12 @@ export default class GoTrueClient {
13341334 headers : this . headers ,
13351335 xform : _ssoResponse ,
13361336 } )
1337+
1338+ // Automatically redirect in browser unless skipBrowserRedirect is true
1339+ if ( result . data ?. url && isBrowser ( ) && ! params . options ?. skipBrowserRedirect ) {
1340+ window . location . assign ( result . data . url )
1341+ }
1342+
13371343 return this . _returnResult ( result )
13381344 } catch ( error ) {
13391345 if ( isAuthError ( error ) ) {
Original file line number Diff line number Diff line change @@ -788,6 +788,12 @@ export type SignInWithSSO =
788788 redirectTo ?: string
789789 /** Verification token received when the user completes the captcha on the site. */
790790 captchaToken ?: string
791+ /**
792+ * If set to true, the redirect will not happen on the client side.
793+ * This parameter is used when you wish to handle the redirect yourself.
794+ * Defaults to false.
795+ */
796+ skipBrowserRedirect ?: boolean
791797 }
792798 }
793799 | {
@@ -799,6 +805,12 @@ export type SignInWithSSO =
799805 redirectTo ?: string
800806 /** Verification token received when the user completes the captcha on the site. */
801807 captchaToken ?: string
808+ /**
809+ * If set to true, the redirect will not happen on the client side.
810+ * This parameter is used when you wish to handle the redirect yourself.
811+ * Defaults to false.
812+ */
813+ skipBrowserRedirect ?: boolean
802814 }
803815 }
804816
Original file line number Diff line number Diff line change @@ -3100,6 +3100,25 @@ describe('SSO Authentication', () => {
31003100 expect ( data ) . toBeNull ( )
31013101 } )
31023102
3103+ test ( 'signInWithSSO should support skipBrowserRedirect option' , async ( ) => {
3104+ // Note: In a browser environment with SAML enabled, signInWithSSO would
3105+ // automatically redirect to the SSO provider unless skipBrowserRedirect is true.
3106+ // This test verifies the option is accepted (actual redirect behavior cannot
3107+ // be tested in Node.js environment)
3108+ const { data, error } = await pkceClient . signInWithSSO ( {
3109+ providerId : 'valid-provider-id' ,
3110+ options : {
3111+ redirectTo : 'http://localhost:3000/callback' ,
3112+ skipBrowserRedirect : true ,
3113+ } ,
3114+ } )
3115+
3116+ // SAML is disabled in test environment, so we expect an error
3117+ expect ( error ) . not . toBeNull ( )
3118+ expect ( error ?. message ) . toContain ( 'SAML 2.0 is disabled' )
3119+ expect ( data ) . toBeNull ( )
3120+ } )
3121+
31033122 test . each ( [
31043123 {
31053124 name : 'with empty options' ,
You can’t perform that action at this time.
0 commit comments