File tree Expand file tree Collapse file tree 1 file changed +17
-7
lines changed
controlplane/src/core/controllers Expand file tree Collapse file tree 1 file changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -400,16 +400,26 @@ const plugin: FastifyPluginCallback<AuthControllerOptions> = function Auth(fasti
400400 // Set the sso cookie.
401401 opts . authUtils . createSsoCookie ( res , ssoSlug ) ;
402402 }
403+ // Determine the target URL
404+ let targetUrl = opts . webBaseUrl ;
403405 if ( redirectURL ) {
404- if ( redirectURL . startsWith ( opts . webBaseUrl ) ) {
405- res . redirect ( redirectURL ) ;
406- } else {
407- res . redirect ( opts . webBaseUrl ) ;
406+ try {
407+ const redirectOrigin = new URL ( redirectURL ) . origin ;
408+ const webBaseOrigin = new URL ( opts . webBaseUrl ) . origin ;
409+ if ( redirectOrigin === webBaseOrigin ) {
410+ targetUrl = redirectURL ;
411+ }
412+ } catch {
413+ // On parse error, keep targetUrl as opts.webBaseUrl
408414 }
409- } else if ( orgs === 0 ) {
410- res . redirect ( opts . webBaseUrl + '?migrate=true' ) ;
415+ }
416+
417+ // Append onboarding parameter if the user has no orgs
418+ if ( orgs === 0 ) {
419+ const separator = targetUrl . includes ( '?' ) ? '&' : '?' ;
420+ res . redirect ( targetUrl + separator + 'onboarding=true' ) ;
411421 } else {
412- res . redirect ( opts . webBaseUrl ) ;
422+ res . redirect ( targetUrl ) ;
413423 }
414424 } catch ( err : any ) {
415425 if ( err instanceof AuthenticationError ) {
You can’t perform that action at this time.
0 commit comments