diff --git a/src/components/agent/AgentHeader/index.tsx b/src/components/agent/AgentHeader/index.tsx index a03d975..2bf4ee0 100644 --- a/src/components/agent/AgentHeader/index.tsx +++ b/src/components/agent/AgentHeader/index.tsx @@ -5,7 +5,7 @@ import './index.css'; import { useAgentInfo } from '@/hooks/useAgentInfo'; const AgentHeader = () => { - const { level, experience, nextLevelExp } = useAgentInfo(); + const { level, experience, nextLevelExp, agentname } = useAgentInfo(); return (
@@ -15,7 +15,7 @@ const AgentHeader = () => {
- Blommy + {agentname} Level {level} diff --git a/src/hooks/useAgentInfo.ts b/src/hooks/useAgentInfo.ts index ebec46a..ada2074 100644 --- a/src/hooks/useAgentInfo.ts +++ b/src/hooks/useAgentInfo.ts @@ -28,10 +28,18 @@ export function useAgentInfo() { return userProfile?.points || 0; }, [userProfile]); + const agentname = useMemo(() => { + if(userProfile?.agentname) { + return userProfile?.agentname; + } + return "Blommy"; + }, [userProfile]); + return { level, experience, nextLevelExp, + agentname, points, refetch, }; diff --git a/src/pages/AgentCustomized/index.tsx b/src/pages/AgentCustomized/index.tsx index 86d2d4b..4922ace 100644 --- a/src/pages/AgentCustomized/index.tsx +++ b/src/pages/AgentCustomized/index.tsx @@ -54,12 +54,14 @@ const AgentCustomized: React.FC = () => { throw new Error('User not logged in'); } + var agentname = name; // 构建profile更新对象 const profileUpdate = { - name, + userId, + agentname, gender, bio: [ - `I'm ${name}, a ${gender.toLowerCase()} agent with ${agentStyle.toLowerCase()} style`, + `I'm ${agentname}, a ${gender.toLowerCase()} agent with ${agentStyle.toLowerCase()} style`, `Specializing in ${agentStyle.toLowerCase()} interactions and responses`, `Ready to engage with unique ${agentStyle.toLowerCase()} perspective`, ], diff --git a/src/pages/Login/index.tsx b/src/pages/Login/index.tsx index cddbb67..f29dd5d 100644 --- a/src/pages/Login/index.tsx +++ b/src/pages/Login/index.tsx @@ -38,32 +38,77 @@ const Login: React.FC = () => { } }; - const handleGoogleAuth = async () => { - setLoading(true); - try { - // Navigate to next page - navigate('/egg-select'); - } catch (err) { - console.error('Google auth error:', err); - setError(err instanceof Error ? err.message : 'Google auth failed'); - } finally { - setLoading(false); + function simpleHash(input: string) { + let hash = 0; + if (input.length === 0) return hash; + + for (let i = 0; i < input.length; i++) { + let char = input.charCodeAt(i); + hash = ((hash << 5) - hash) + char; + hash |= 0; } - }; - const handleGuest = async () => { + return hash.toString(); + } + + function generateGuestName() { + const timestamp = Date.now(); + const randomNum = Math.floor(Math.random() * 10000); + return "Guest-" + timestamp + randomNum; + } + + function generateGuestPassword(name: string) { + return simpleHash(name).toString(); + } + + + function generateGuestEmail() { + return "Guest@placeholder.com"; + } + + const handleGuestAuth = async () => { + const userId = localStorage.getItem('userId'); + const userProfile = localStorage.getItem('userProfile'); + const twitterProfile = localStorage.getItem('twitterProfile'); + console.log("Guest info: " + userId + " " + userProfile?.toString().length + " " + twitterProfile?.toString().length); + + if (userId && userProfile) { + navigate('/plugin/chat'); // already login + return; + } setLoading(true); try { + // Guest + const username = generateGuestName(); + const password = generateGuestPassword(username); + const email = generateGuestEmail(); + const credentials = { username, password, email }; + const response = await authService.guestLogin(credentials); + console.log("guest auth, res: " + response); // Navigate to next page navigate('/egg-select'); } catch (err) { - console.error('Guest error:', err); - setError(err instanceof Error ? err.message : 'Guest login failed'); + console.error('Guest auth error:', err); + setError(err instanceof Error ? err.message : 'Guest authentication failed'); } finally { setLoading(false); } }; + const handleGoogleAuth = async () => { + setLoading(true); + try { + // Navigate to next page + navigate('/egg-select'); + } catch (err) { + console.error('Google auth error:', err); + setError(err instanceof Error ? err.message : 'Google auth failed'); + } finally { + setLoading(false); + } + }; + + return (
@@ -120,7 +165,7 @@ const Login: React.FC = () => {