Skip to content

Commit

Permalink
fix: anonymous users accessing the dashboard are forced to log in (#344)
Browse files Browse the repository at this point in the history
* fix: anonymous users accessing the dashboard are forced to log in

* fix: fix cr
  • Loading branch information
xingwanying authored Sep 4, 2024
1 parent 8a62e8a commit 581900a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
16 changes: 13 additions & 3 deletions client/app/factory/edit/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import BotCreateFrom from '@/app/factory/edit/components/BotCreateFrom';
import { toast, ToastContainer } from 'react-toastify';
import BackIcon from '@/public/icons/BackIcon';
import { CopyToClipboard } from 'react-copy-to-clipboard';
import { useRouter } from 'next/navigation';
import {
useBotConfigGenerator,
useBotConfig,
Expand All @@ -20,12 +21,13 @@ import ChatIcon from '@/public/icons/ChatIcon';
import ConfigIcon from '@/public/icons/ConfigIcon';
import SaveIcon from '@/public/icons/SaveIcon';
import { useBot } from '@/app/contexts/BotContext';

import 'react-toastify/dist/ReactToastify.css';
import useUser from '@/app/hooks/useUser';
import Knowledge from '../components/Knowledge';
import KnowledgeBtn from '../components/KnowledgeBtn';
import { BotTaskProvider } from '../components/TaskContext';

import 'react-toastify/dist/ReactToastify.css';

const API_HOST = process.env.NEXT_PUBLIC_API_DOMAIN;
enum VisibleTypeEnum {
BOT_CONFIG = 'BOT_CONFIG',
Expand All @@ -37,13 +39,21 @@ enum ConfigTypeEnum {
}
export default function Edit({ params }: { params: { id: string } }) {
const { botProfile, setBotProfile } = useBot();

const { data: user, status } = useUser();
const router = useRouter();
const [activeTab, setActiveTab] = React.useState<ConfigTypeEnum>(
ConfigTypeEnum.CHAT_CONFIG,
);
const [visibleType, setVisibleType] = React.useState<VisibleTypeEnum>(
VisibleTypeEnum.BOT_CONFIG,
);
const apiDomain = process.env.NEXT_PUBLIC_API_DOMAIN;

useEffect(() => {
if (!user || status !== 'success' || user.id.startsWith('client|')) {
router.push(`${apiDomain}/api/auth/login`);
}
}, [user, status]);

const {
updateBot: onUpdateBot,
Expand Down
17 changes: 15 additions & 2 deletions server/agent/prompts/bot_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
- Can only create a Q&A bot or update the configuration of the bot based on the GitHub repository information provided by the user.
- During the process of creating a Q&A bot, if any issues or errors are encountered, you may provide related advice or solutions, but must not directly modify the user's GitHub repository.
- When modifying the bot's configuration information, you must adhere to the user's suggestions and requirements and not make changes without permission.
- Whenever you encounter a 401 or Unauthorized error that seems to be an authentication failure, please inform the user in the language they are using to converse with you. For example:
If user is conversing with you in Chinese:
“您必须先使用 GitHub 登录 Petercat 才能使用此功能。[登录地址](https://api.petercat.ai/api/auth/login)
If user is conversing with you in English:
“You must log in to Petercat using GitHub before accessing this feature.” [Login URL](https://api.petercat.ai/api/auth/login)
"""

EDIT_PROMPT = """
Expand All @@ -45,11 +52,17 @@
- Can only update the configuration of the bot based on the GitHub repository information provided by the user.
- During the process of a Q&A bot, if any issues or errors are encountered, you may provide related advice or solutions, but must not directly modify the user's GitHub repository.
- When modifying the bot's configuration information, you must adhere to the user's suggestions and requirements and not make changes without permission.
If user is conversing with you in Chinese:
“您必须先使用 GitHub 登录 Petercat 才能使用此功能。[登录地址](https://api.petercat.ai/api/auth/login)
If user is conversing with you in English:
“You must log in to Petercat using GitHub before accessing this feature.” [Login URL](https://api.petercat.ai/api/auth/login)
"""


def generate_prompt_by_user_id(user_id: str, bot_id: Optional[str]):
if bot_id:
return EDIT_PROMPT.format(bot_id=bot_id, user_id=user_id)
return EDIT_PROMPT.format(bot_id=bot_id, user_id=user_id)
else:
return CREATE_PROMPT.format(user_id=user_id)
return CREATE_PROMPT.format(user_id=user_id)

0 comments on commit 581900a

Please sign in to comment.