@@ -112,7 +112,7 @@ const UpgradeToProModal = ({ isOpen, onClose }) => {
112112 const handleUpgrade = ( ) => {
113113 const dashboardUrl = process . env . NEXT_PUBLIC_LANDING_PAGE_URL
114114 if ( dashboardUrl ) {
115- window . open ( `${ dashboardUrl } /dashboard` , "_blank" )
115+ window . location . href = `${ dashboardUrl } /dashboard`
116116 }
117117 onClose ( )
118118 }
@@ -714,7 +714,9 @@ const IntegrationsPage = () => {
714714 const fetchIntegrations = useCallback ( async ( ) => {
715715 setLoading ( true )
716716 try {
717- const response = await fetch ( "/api/settings/integrations" )
717+ const response = await fetch ( "/api/settings/integrations" , {
718+ cache : "no-store"
719+ } )
718720 const data = await response . json ( )
719721 if ( ! response . ok )
720722 throw new Error ( data . error || "Failed to fetch integrations" )
@@ -756,7 +758,29 @@ const IntegrationsPage = () => {
756758 setUpgradeModalOpen ( true )
757759 }
758760
759- const handleConnect = ( integration ) => {
761+ const handleConnect = async ( integration ) => {
762+ const isProFeature = PRO_ONLY_INTEGRATIONS . includes ( integration . name )
763+ if ( isProFeature && ! isPro ) {
764+ handleUpgradeClick ( )
765+ return
766+ }
767+
768+ // If it's a pro feature, refresh the session cookie before redirecting
769+ // to ensure the backend gets a fresh token with the correct roles.
770+ if ( isProFeature ) {
771+ const toastId = toast . loading ( "Preparing secure connection..." )
772+ try {
773+ const res = await fetch ( "/api/auth/refresh-session" )
774+ if ( ! res . ok ) throw new Error ( "Session refresh failed" )
775+ toast . dismiss ( toastId )
776+ } catch ( e ) {
777+ toast . error ( "Could not prepare connection. Please try again." , {
778+ id : toastId
779+ } )
780+ return // Stop if refresh fails
781+ }
782+ }
783+
760784 if ( integration . name === "whatsapp" ) {
761785 setWhatsAppToConnect ( integration )
762786 return
@@ -1257,17 +1281,17 @@ const IntegrationsPage = () => {
12571281 </ button >
12581282 ) : (
12591283 < button
1260- onClick = { ( e ) => {
1284+ onClick = { async ( e ) => {
12611285 e . stopPropagation ( )
12621286 if (
12631287 integration . auth_type ===
12641288 "composio"
12651289 ) {
1266- handleComposioConnect (
1290+ await handleComposioConnect (
12671291 integration
12681292 )
12691293 } else {
1270- handleConnect ( integration )
1294+ await handleConnect ( integration )
12711295 }
12721296 } }
12731297 className = "flex items-center justify-center gap-2 w-full py-2 px-3 rounded-md bg-brand-orange hover:bg-brand-orange/90 text-brand-black font-semibold text-sm transition-colors"
@@ -1452,4 +1476,4 @@ const IntegrationsPage = () => {
14521476 )
14531477}
14541478
1455- export default IntegrationsPage
1479+ export default IntegrationsPage
0 commit comments