diff --git a/.gitignore b/.gitignore
index b7fe63c..4ece70c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -37,3 +37,5 @@ yarn-error.log*
next-env.d.ts
.idea
+
+.env.docker
\ No newline at end of file
diff --git a/src/app/api/assistants/[id]/route.ts b/src/app/api/assistants/[id]/route.ts
index dc7f187..eb1afd4 100644
--- a/src/app/api/assistants/[id]/route.ts
+++ b/src/app/api/assistants/[id]/route.ts
@@ -37,6 +37,14 @@ export async function GET(req: NextRequest, res: NextResponse) {
);
}
+ if (assistant.authenticatedUsersOnly) {
+ // Validate that the user is logged in when this condition is applied
+ const session = await getSession();
+ if (!session?.user) {
+ return Response.json({ message: 'Unauthenticated' }, { status: 401 });
+ }
+ }
+
// Inject customization properties into the assistant object
if (assistant.object) {
// @ts-ignore
diff --git a/src/app/api/auth/[auth0]/route.ts b/src/app/api/auth/[auth0]/route.ts
index 31e8488..9e91a52 100644
--- a/src/app/api/auth/[auth0]/route.ts
+++ b/src/app/api/auth/[auth0]/route.ts
@@ -1,7 +1,21 @@
import { handleAuth, handleLogin } from '@auth0/nextjs-auth0';
+import { redirect } from 'next/navigation';
export const GET = handleAuth({
- login: handleLogin({
- returnTo: '/assistants',
+ login: handleLogin((req) => {
+ let returnUrl = '/assistants';
+
+ // @ts-ignore
+ if (req.url && req.url.searchParams) {
+ // @ts-ignore
+ let redirectUrl = req.url.searchParams.get('returnTo');
+ if (redirectUrl) {
+ returnUrl = redirectUrl;
+ }
+ }
+
+ return {
+ returnTo: returnUrl,
+ };
}),
});
diff --git a/src/app/assistants/ListAssistants.tsx b/src/app/assistants/ListAssistants.tsx
index 8147727..5992b48 100644
--- a/src/app/assistants/ListAssistants.tsx
+++ b/src/app/assistants/ListAssistants.tsx
@@ -17,7 +17,9 @@ import {
HiCog,
HiColorSwatch,
HiFolder,
+ HiGlobeAlt,
HiLink,
+ HiOutlineLockClosed,
HiPlus,
HiPuzzle,
} from 'react-icons/hi';
@@ -90,6 +92,11 @@ export default function ListAssistants() {
className={'pb-1'}
/>
+ {assistant.authenticatedUsersOnly ? (
+
+ ) : (
+
+ )}
{assistant.name}
@@ -97,7 +104,7 @@ export default function ListAssistants() {
{assistant.modelId}
- {assistant.published ? 'Public' : 'Private'}
+ {assistant.published ? 'Listed' : 'Private'}
diff --git a/src/app/assistants/[id]/chat/ChatAgent.tsx b/src/app/assistants/[id]/chat/ChatAgent.tsx
index 21b7272..e862d3e 100644
--- a/src/app/assistants/[id]/chat/ChatAgent.tsx
+++ b/src/app/assistants/[id]/chat/ChatAgent.tsx
@@ -1,6 +1,5 @@
'use client';
-import ChatPopup from '@/app/assistants/[id]/chat/ChatPopup';
import { Avatar, Dropdown, Spinner, Button } from 'flowbite-react';
import { getImageHash } from '@/app/utils/hash';
import { updateAssistant, useGetAssistant } from '@/app/assistants/[id]/client';
@@ -8,6 +7,7 @@ import React, { useEffect, useState } from 'react';
import { Assistant } from '@/app/types/assistant';
import AssistantContext from '@/app/assistants/[id]/AssistantContext';
import ChatPopupFrame from '@/app/assistants/[id]/chat/ChatPopupFrame';
+import { useRouter } from 'next/navigation';
export interface ChatAgentProps {
assistant_id: string;
@@ -25,9 +25,15 @@ export default function ChatAgent(props: ChatAgentProps) {
const [loading, setLoading] = useState(true);
const [assistant, setAssistant] = useState
(assistantResponse);
+ const { push } = useRouter();
+
useEffect(() => {
if (assistantResponse) {
setAssistant(assistantResponse);
+ // @ts-ignore
+ if (assistantResponse && assistantResponse.message) {
+ push('/api/auth/login?returnTo=/embed/' + props.assistant_id);
+ }
setLoading(false);
}
}, [assistantLoading]);
@@ -95,12 +101,14 @@ export default function ChatAgent(props: ChatAgentProps) {
getAssistantAvatar()
)}
- ) : (
+ ) : assistant.id ? (
+ ) : (
+ <>Redirecting...>
)}
diff --git a/src/app/assistants/[id]/chat/ChatPageContextWrapper.tsx b/src/app/assistants/[id]/chat/ChatPageContextWrapper.tsx
index f91bb4e..65daa51 100644
--- a/src/app/assistants/[id]/chat/ChatPageContextWrapper.tsx
+++ b/src/app/assistants/[id]/chat/ChatPageContextWrapper.tsx
@@ -4,6 +4,7 @@ import { Assistant } from '@/app/types/assistant';
import ChatPage from '@/app/assistants/[id]/chat/ChatPage';
import { Spinner } from 'flowbite-react';
import AssistantContext from '@/app/assistants/[id]/AssistantContext';
+import { useRouter } from 'next/navigation';
export default function ChatPageContextWrapper(props: { assistantId: string }) {
let { assistantLoading, assistantResponse, assistantEmpty, reload } =
@@ -12,9 +13,15 @@ export default function ChatPageContextWrapper(props: { assistantId: string }) {
const [loading, setLoading] = useState(true);
const [assistant, setAssistant] = useState(assistantResponse);
+ const { push } = useRouter();
+
useEffect(() => {
if (assistantResponse) {
setAssistant(assistantResponse);
+ // @ts-ignore
+ if (assistantResponse && assistantResponse.message) {
+ push('/api/auth/login?returnTo=/link/' + props.assistantId);
+ }
setLoading(false);
}
}, [assistantLoading]);
@@ -28,11 +35,13 @@ export default function ChatPageContextWrapper(props: { assistantId: string }) {
- ) : (
+ ) : assistant.id ? (
+ ) : (
+ <>Redirecting...>
);
}
diff --git a/src/app/assistants/[id]/chat/ChatWindow.tsx b/src/app/assistants/[id]/chat/ChatWindow.tsx
index d56ee99..69916d0 100644
--- a/src/app/assistants/[id]/chat/ChatWindow.tsx
+++ b/src/app/assistants/[id]/chat/ChatWindow.tsx
@@ -7,6 +7,7 @@ import React, { useEffect, useState } from 'react';
import { Assistant } from '@/app/types/assistant';
import AssistantContext from '@/app/assistants/[id]/AssistantContext';
import ChatPopupFrame from '@/app/assistants/[id]/chat/ChatPopupFrame';
+import { useRouter } from 'next/navigation';
export interface ChatWindowProps {
assistant_id: string;
@@ -25,9 +26,15 @@ export default function ChatWindow(props: ChatWindowProps) {
const [loading, setLoading] = useState(true);
const [assistant, setAssistant] = useState(assistantResponse);
+ const { push } = useRouter();
+
useEffect(() => {
if (assistantResponse) {
setAssistant(assistantResponse);
+ // @ts-ignore
+ if (assistantResponse && assistantResponse.message) {
+ push('/api/auth/login?returnTo=/embed/' + props.assistant_id);
+ }
setLoading(false);
}
}, [assistantLoading]);
@@ -47,7 +54,7 @@ export default function ChatWindow(props: ChatWindowProps) {
aria-label='Loading assistant..'
className={'self-center p-10'}
/>
- ) : (
+ ) : assistant.id ? (
@@ -57,6 +64,8 @@ export default function ChatWindow(props: ChatWindowProps) {
)}
+ ) : (
+ <>Redirecting...>
)}
diff --git a/src/app/link/[id]/page.tsx b/src/app/link/[id]/page.tsx
index cb4b204..fa116a3 100644
--- a/src/app/link/[id]/page.tsx
+++ b/src/app/link/[id]/page.tsx
@@ -1,8 +1,6 @@
'use client';
import { useParams } from 'next/navigation';
-import ChatWindow from '@/app/assistants/[id]/chat/ChatWindow';
-import ChatPage from '@/app/assistants/[id]/chat/ChatPage';
import ChatPageContextWrapper from '@/app/assistants/[id]/chat/ChatPageContextWrapper';
export interface ChatComponentProps {