Skip to content

SmythOS Studio: Open-Source Visual AI Agent Builder and deployable runtime stack from SmythOS. Start with an intuitive drag-and-drop workspace, extend with custom code, and deploy your agents anywhere — local, cloud, or edge — with full governance and control.

refactor: update OAuth overlay to use dynamic authentication URL

Muhammad Hamza Khan9d87ccf3e445
diff --git a/packages/app/src/react/features/ai-chat/components/auth/oauth-overlay.tsx b/packages/app/src/react/features/ai-chat/components/auth/oauth-overlay.tsx
index 05f4f081..257f1bbb 100644
--- a/packages/app/src/react/features/ai-chat/components/auth/oauth-overlay.tsx
+++ b/packages/app/src/react/features/ai-chat/components/auth/oauth-overlay.tsx
@@ -1,7 +1,7 @@
import { useChatStores } from '@react/features/ai-chat/hooks';
import { Button } from '@react/shared/components/ui/button';
import { Spinner } from '@react/shared/components/ui/spinner';
-import { useCallback, useEffect, useRef, useState } from 'react';
+import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
/**
* OAuth sign-in overlay component
@@ -9,7 +9,11 @@ import { useCallback, useEffect, useRef, useState } from 'react';
*/
export const OAuthOverlay = () => {
const { auth } = useChatStores();
- const { authorizationUrl, onAuthSuccess } = auth;
+ const { onAuthSuccess, redirectInternalEndpoint, domain } = auth;
+
+ const oAuthUrl = useMemo(() => {
+ return `https://${domain}${redirectInternalEndpoint}`;
+ }, [domain, redirectInternalEndpoint]);
const [isLoading, setIsLoading] = useState(false);
const [popupBlocked, setPopupBlocked] = useState(false);
@@ -45,10 +49,10 @@ export const OAuthOverlay = () => {
}, [isLoading]);
const handleSignIn = useCallback(() => {
- if (!authorizationUrl) return;
+ if (!oAuthUrl) return;
setPopupBlocked(false);
- const popup = window.open(authorizationUrl, '_blank', 'width=500,height=600');
+ const popup = window.open(oAuthUrl, '_blank', 'width=500,height=600');
if (!popup || popup.closed) {
setPopupBlocked(true);
@@ -57,7 +61,7 @@ export const OAuthOverlay = () => {
popupRef.current = popup;
setIsLoading(true);
- }, [authorizationUrl]);
+ }, [oAuthUrl]);
return (
<div className="space-y-4">
@@ -82,7 +86,7 @@ export const OAuthOverlay = () => {
<p className="text-sm text-yellow-800">
Popup was blocked. Please allow popups for this site or{' '}
<a
- href={authorizationUrl}
+ href={oAuthUrl}
target="_blank"
rel="noopener noreferrer"
className="underline font-medium"
diff --git a/packages/app/src/react/features/ai-chat/contexts/chat.provider.tsx b/packages/app/src/react/features/ai-chat/contexts/chat.provider.tsx
index 823cc0d1..0a6387ef 100644
--- a/packages/app/src/react/features/ai-chat/contexts/chat.provider.tsx
+++ b/packages/app/src/react/features/ai-chat/contexts/chat.provider.tsx
@@ -201,6 +201,8 @@ export const ChatContextProvider: FC<TChildren> = ({ children }) => {
isRequired: (chatParams?.authRequired && !isAuthOverridden) || false,
method: chatParams?.auth?.method,
authorizationUrl: chatParams?.auth?.authorizationUrl,
+ redirectInternalEndpoint: chatParams?.auth?.redirectInternalEndpoint,
+ domain: chatParams?.domain,
onAuthSuccess: handleAuthSuccess,
},
pageState,
diff --git a/packages/app/src/react/features/ai-chat/contexts/chat.ts b/packages/app/src/react/features/ai-chat/contexts/chat.ts
index 7f67217b..b3968f05 100644
--- a/packages/app/src/react/features/ai-chat/contexts/chat.ts
+++ b/packages/app/src/react/features/ai-chat/contexts/chat.ts
@@ -39,6 +39,8 @@ export interface IChatContext {
method?: string;
authorizationUrl?: string;
onAuthSuccess: () => Promise<void>;
+ redirectInternalEndpoint?: string;
+ domain?: string;
};
pageState: TPageState;
}
@@ -51,33 +53,35 @@ export const ChatContext = createContext<IChatContext>({
status: {},
uploading: false,
errorMessage: '',
- addFiles: async () => {},
- remove: () => {},
- clear: () => {},
- clearError: () => {},
- removeByIds: () => {},
+ addFiles: async () => { },
+ remove: () => { },
+ clear: () => { },
+ clearError: () => { },
+ removeByIds: () => { },
},
chat: {
isChatCreating: false,
messages: [],
isStreaming: false,
- sendMessage: async () => {},
- retryMessage: async () => {},
- stopStreaming: () => {},
- resetSession: async () => {},
+ sendMessage: async () => { },
+ retryMessage: async () => { },
+ stopStreaming: () => { },
+ resetSession: async () => { },
},
scroll: {
showScrollButton: false,
- handleScroll: () => {},
- scrollToBottom: () => {},
- smartScrollToBottom: () => {},
- hideScrollButton: () => {},
+ handleScroll: () => { },
+ scrollToBottom: () => { },
+ smartScrollToBottom: () => { },
+ hideScrollButton: () => { },
},
modelOverride: null,
- setModelOverride: () => {},
+ setModelOverride: () => { },
auth: {
isRequired: false,
- onAuthSuccess: async () => {},
+ onAuthSuccess: async () => { },
+ redirectInternalEndpoint: '',
+ domain: '',
},
pageState: 'loading',
});