From 719dab21a9e40088cac6b1cec17741ade5515e80 Mon Sep 17 00:00:00 2001 From: "raoha.rh" Date: Tue, 17 Dec 2024 18:05:37 +0800 Subject: [PATCH] feat: support locally auth --- assistant/package.json | 2 +- assistant/src/Chat/template/LoginCard.tsx | 4 ++-- assistant/src/Chat/template/index.tsx | 8 ++++++-- assistant/src/hooks/useUser.ts | 5 +++-- assistant/src/style.css | 24 +++++++++++------------ client/app/hooks/useUser.ts | 1 + client/components/User.tsx | 1 - client/package.json | 2 +- client/yarn.lock | 8 ++++---- 9 files changed, 30 insertions(+), 25 deletions(-) diff --git a/assistant/package.json b/assistant/package.json index 86c23827..952b86c3 100644 --- a/assistant/package.json +++ b/assistant/package.json @@ -1,6 +1,6 @@ { "name": "@petercatai/assistant", - "version": "1.0.20", + "version": "1.0.22", "description": "PeterCat Assistant Application", "module": "dist/esm/index.js", "types": "dist/esm/index.d.ts", diff --git a/assistant/src/Chat/template/LoginCard.tsx b/assistant/src/Chat/template/LoginCard.tsx index 03ac5a6a..573997e7 100644 --- a/assistant/src/Chat/template/LoginCard.tsx +++ b/assistant/src/Chat/template/LoginCard.tsx @@ -4,8 +4,8 @@ import { Button } from 'antd'; import GitHubIcon from '../../icons/GitHubIcon'; import useUser from '../../hooks/useUser'; -const LoginCard = ({ apiDomain, token }: { apiDomain: string; token: string; }) => { - const { user, isLoading, actions } = useUser({ apiDomain, fingerprint: token }); +const LoginCard = ({ apiDomain, webDomain, token }: { apiDomain: string; webDomain?: string; token: string; }) => { + const { user, isLoading, actions } = useUser({ apiDomain, webDomain, fingerprint: token }); if (isLoading) { return diff --git a/assistant/src/Chat/template/index.tsx b/assistant/src/Chat/template/index.tsx index 0a81ec9f..49155493 100644 --- a/assistant/src/Chat/template/index.tsx +++ b/assistant/src/Chat/template/index.tsx @@ -2,7 +2,7 @@ import React from 'react'; import GitInsightCard from './GitInsightCard'; import LoginCard from './LoginCard'; -export const UITemplateRender = ({ templateId, apiDomain, token, cardData }: { templateId: string, apiDomain: string; token: string; cardData: any }) => { +export const UITemplateRender = ({ templateId, apiDomain, webDomain, token, cardData }: { templateId: string, apiDomain: string; webDomain?: string; token: string; cardData: any }) => { if (templateId === 'GIT_INSIGHT') { return ( + ); } return null; diff --git a/assistant/src/hooks/useUser.ts b/assistant/src/hooks/useUser.ts index c0bc06b5..c16113bd 100644 --- a/assistant/src/hooks/useUser.ts +++ b/assistant/src/hooks/useUser.ts @@ -5,7 +5,7 @@ import useSWR from 'swr'; import { popupCenter } from '../utils/popcenter'; import { useEffect } from 'react'; -function useUser({ apiDomain, fingerprint }: { apiDomain: string; fingerprint: string }) { +function useUser({ apiDomain, webDomain = 'https://petercat.ai', fingerprint }: { apiDomain: string; fingerprint: string; webDomain?: string }) { const { data: user, isLoading, mutate } = useSWR( ['user.info'], async () => getUserInfo(apiDomain, { clientId: fingerprint }), @@ -14,8 +14,9 @@ function useUser({ apiDomain, fingerprint }: { apiDomain: string; fingerprint: s const doLogin = () => { + console.log('call do Login', webDomain); popupCenter({ - url: 'https://petercat.ai/user/login', + url: `${webDomain}/user/login`, title: 'Login', w: 600, h: 400, diff --git a/assistant/src/style.css b/assistant/src/style.css index fb35752c..db155add 100644 --- a/assistant/src/style.css +++ b/assistant/src/style.css @@ -112,8 +112,8 @@ */ *:where(.petercat-lui,.petercat-lui *), -:where(.petercat-lui,.petercat-lui *)::before, -:where(.petercat-lui,.petercat-lui *)::after { +::before:where(.petercat-lui,.petercat-lui *), +::after:where(.petercat-lui,.petercat-lui *) { box-sizing: border-box; /* 1 */ border-width: 0; @@ -124,8 +124,8 @@ /* 2 */ } -:where(.petercat-lui,.petercat-lui *)::before, -:where(.petercat-lui,.petercat-lui *)::after { +::before:where(.petercat-lui,.petercat-lui *), +::after:where(.petercat-lui,.petercat-lui *) { --tw-content: ''; } @@ -378,8 +378,8 @@ progress:where(.petercat-lui,.petercat-lui *) { Correct the cursor style of increment and decrement buttons in Safari. */ -:where(.petercat-lui,.petercat-lui *) ::-webkit-inner-spin-button, -:where(.petercat-lui,.petercat-lui *) ::-webkit-outer-spin-button { +::-webkit-inner-spin-button:where(.petercat-lui,.petercat-lui *), +::-webkit-outer-spin-button:where(.petercat-lui,.petercat-lui *) { height: auto; } @@ -399,7 +399,7 @@ Correct the cursor style of increment and decrement buttons in Safari. Remove the inner padding in Chrome and Safari on macOS. */ -:where(.petercat-lui,.petercat-lui *) ::-webkit-search-decoration { +::-webkit-search-decoration:where(.petercat-lui,.petercat-lui *) { -webkit-appearance: none; } @@ -408,7 +408,7 @@ Remove the inner padding in Chrome and Safari on macOS. 2. Change font properties to `inherit` in Safari. */ -:where(.petercat-lui,.petercat-lui *) ::-webkit-file-upload-button { +::-webkit-file-upload-button:where(.petercat-lui,.petercat-lui *) { -webkit-appearance: button; /* 1 */ font: inherit; @@ -481,15 +481,15 @@ textarea:where(.petercat-lui,.petercat-lui *) { 2. Set the default placeholder color to the user's configured gray 400 color. */ -:where(.petercat-lui,.petercat-lui *) input::-moz-placeholder, :where(.petercat-lui,.petercat-lui *) textarea::-moz-placeholder { +input::-moz-placeholder:where(.petercat-lui,.petercat-lui *), textarea::-moz-placeholder:where(.petercat-lui,.petercat-lui *) { opacity: 1; /* 1 */ color: #9ca3af; /* 2 */ } -:where(.petercat-lui,.petercat-lui *) input::placeholder, -:where(.petercat-lui,.petercat-lui *) textarea::placeholder { +input::placeholder:where(.petercat-lui,.petercat-lui *), +textarea::placeholder:where(.petercat-lui,.petercat-lui *) { opacity: 1; /* 1 */ color: #9ca3af; @@ -545,7 +545,7 @@ video:where(.petercat-lui,.petercat-lui *) { /* Make elements with the HTML hidden attribute stay hidden by default */ -[hidden]:where(:not([hidden="until-found"])):where(.petercat-lui,.petercat-lui *) { +[hidden]:where(.petercat-lui,.petercat-lui *) { display: none; } diff --git a/client/app/hooks/useUser.ts b/client/app/hooks/useUser.ts index 53099261..2099af71 100644 --- a/client/app/hooks/useUser.ts +++ b/client/app/hooks/useUser.ts @@ -10,6 +10,7 @@ export const useUser = () => { const { data: fingerprint } = useFingerprint(); const { user, isLoading, actions } = useAssistUser({ apiDomain: API_DOMAIN, + webDomain: '', fingerprint: fingerprint?.visitorId!, }); diff --git a/client/components/User.tsx b/client/components/User.tsx index 0677a2b3..887a9068 100644 --- a/client/components/User.tsx +++ b/client/components/User.tsx @@ -1,6 +1,5 @@ 'use client'; import I18N from '@/app/utils/I18N'; -import { useRouter } from 'next/navigation'; import { Avatar, Button, diff --git a/client/package.json b/client/package.json index 9aeb5350..6b54fa7b 100644 --- a/client/package.json +++ b/client/package.json @@ -22,7 +22,7 @@ "@fullpage/react-fullpage": "^0.1.42", "@next/bundle-analyzer": "^13.4.19", "@nextui-org/react": "^2.2.9", - "@petercatai/assistant": "1.0.20", + "@petercatai/assistant": "1.0.22", "@sentry/nextjs": "^8.28.0", "@supabase/supabase-js": "^2.32.0", "@tanstack/react-query": "^5.17.19", diff --git a/client/yarn.lock b/client/yarn.lock index 7278dc7b..8efbf301 100644 --- a/client/yarn.lock +++ b/client/yarn.lock @@ -2842,10 +2842,10 @@ resolved "https://registry.yarnpkg.com/@panva/hkdf/-/hkdf-1.2.1.tgz#cb0d111ef700136f4580349ff0226bf25c853f23" integrity sha512-6oclG6Y3PiDFcoyk8srjLfVKyMfVCKJ27JwNPViuXziFpmdz+MZnZN/aKY0JGXgYuO/VghU0jcOAZgWXZ1Dmrw== -"@petercatai/assistant@1.0.20": - version "1.0.20" - resolved "https://registry.yarnpkg.com/@petercatai/assistant/-/assistant-1.0.20.tgz#2d2dc1beb296c8524219a6de7eee1575cb3b4c92" - integrity sha512-csfRRsKB9FbBM+cMcCTQQowsuuFRVerSrxfMRTWoI1XHhBW3ormbt1XTeYKiubmwz4iKznR+2UCrZrCl75ckmA== +"@petercatai/assistant@1.0.22": + version "1.0.22" + resolved "https://registry.yarnpkg.com/@petercatai/assistant/-/assistant-1.0.22.tgz#a4113bf4eae9dc66ad0f0e2b33b1f579ca1252a2" + integrity sha512-E8uMZRK3bdD9Oh2mQhK6Zd2A+KV6dt/H2F/fnv/cBT6KOdywwDQIx94K/2fTcpZJXPsUCTMcOhl2877FNaJkxQ== dependencies: "@ant-design/icons" "^5.3.5" "@ant-design/pro-chat" "^1.9.0"