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 @@ -786,6 +786,12 @@ export type SignInWithSSO =
786786 redirectTo ?: string
787787 /** Verification token received when the user completes the captcha on the site. */
788788 captchaToken ?: string
789+ /**
790+ * If set to true, the redirect will not happen on the client side.
791+ * This parameter is used when you wish to handle the redirect yourself.
792+ * Defaults to false.
793+ */
794+ skipBrowserRedirect ?: boolean
789795 }
790796 }
791797 | {
@@ -797,6 +803,12 @@ export type SignInWithSSO =
797803 redirectTo ?: string
798804 /** Verification token received when the user completes the captcha on the site. */
799805 captchaToken ?: string
806+ /**
807+ * If set to true, the redirect will not happen on the client side.
808+ * This parameter is used when you wish to handle the redirect yourself.
809+ * Defaults to false.
810+ */
811+ skipBrowserRedirect ?: boolean
800812 }
801813 }
802814
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