From 773ab138ca7cb421a93a04ca11bd5f52ee374b77 Mon Sep 17 00:00:00 2001 From: Ou Date: Sun, 3 Nov 2024 20:13:49 +0800 Subject: [PATCH] feat: refactor login --- server/api/enable-login.ts | 8 ++++++++ src/components/column/card.tsx | 4 ++-- src/components/column/dnd.tsx | 5 +++-- src/components/header/menu.tsx | 8 ++++---- src/hooks/useLogin.ts | 25 +++++++++++++++++++++++-- src/hooks/useRefetch.ts | 24 ++++++++++++++++++------ src/hooks/useSync.ts | 4 ++-- src/main.tsx | 2 -- src/routes/__root.tsx | 8 -------- src/utils/index.ts | 1 + src/vite-env.d.ts | 1 - vite.config.ts | 8 -------- 12 files changed, 61 insertions(+), 37 deletions(-) create mode 100644 server/api/enable-login.ts diff --git a/server/api/enable-login.ts b/server/api/enable-login.ts new file mode 100644 index 0000000..a018f6e --- /dev/null +++ b/server/api/enable-login.ts @@ -0,0 +1,8 @@ +import process from "node:process" + +export default defineEventHandler(async () => { + return { + enable: true, + url: `https://github.com/login/oauth/authorize?client_id=${process.env.G_CLIENT_ID}`, + } +}) diff --git a/src/components/column/card.tsx b/src/components/column/card.tsx index 8948142..46b881b 100644 --- a/src/components/column/card.tsx +++ b/src/components/column/card.tsx @@ -53,10 +53,10 @@ function NewsCard({ id, handleListeners }: NewsCardProps) { queryKey: [id, getRefreshId(id)], queryFn: async ({ queryKey }) => { const [_id, _refetchTime] = queryKey as [SourceID, number] - let url = `/api/s?id=${_id}` + let url = `/s?id=${_id}` const headers: Record = {} if (Date.now() - _refetchTime < 1000) { - url = `/api/s?id=${_id}&latest` + url = `/s?id=${_id}&latest` const jwt = safeParseString(localStorage.getItem("jwt")) if (jwt) headers.Authorization = `Bearer ${jwt}` } else if (cache.has(_id)) { diff --git a/src/components/column/dnd.tsx b/src/components/column/dnd.tsx index 1f2bb2a..5d11213 100644 --- a/src/components/column/dnd.tsx +++ b/src/components/column/dnd.tsx @@ -25,10 +25,11 @@ import { currentSourcesAtom } from "~/atoms" export function Dnd() { const [items, setItems] = useAtom(currentSourcesAtom) useQuery({ - queryKey: ["entries", items.sort()], + // sort in place + queryKey: ["entries", [...items].sort()], queryFn: async ({ queryKey }) => { const sources = queryKey[1] - const res: EntriesSourceResponse = await myFetch("/api/s/entries", { + const res: EntriesSourceResponse = await myFetch("/s/entries", { method: "POST", body: { sources, diff --git a/src/components/header/menu.tsx b/src/components/header/menu.tsx index b969338..dc150b7 100644 --- a/src/components/header/menu.tsx +++ b/src/components/header/menu.tsx @@ -14,7 +14,7 @@ function ThemeToggle() { } export function Menu() { - const { loggedIn, login, logout, userInfo } = useLogin() + const { loggedIn, login, logout, userInfo, enableLogin } = useLogin() const [shown, show] = useState(false) const ref = useRef(null) const isHover = useHoverDirty(ref) @@ -25,7 +25,7 @@ export function Menu() { { - loggedIn && userInfo.avatar + enableLogin && loggedIn && userInfo.avatar ? (