From d02c5784406439b73aa2bf04176746879dbea9fa Mon Sep 17 00:00:00 2001 From: gww Date: Thu, 16 Apr 2026 18:43:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/auth-client.ts | 4 +--- src/lib/wechat.ts | 17 --------------- src/pages/wechat-demo.tsx | 45 ++++++--------------------------------- vite.config.ts | 12 ++++++++++- 4 files changed, 18 insertions(+), 60 deletions(-) diff --git a/src/lib/auth-client.ts b/src/lib/auth-client.ts index 545aeeb..d56dcb2 100644 --- a/src/lib/auth-client.ts +++ b/src/lib/auth-client.ts @@ -1,8 +1,6 @@ import { createAuthClient } from "better-auth/react"; -const baseURL = ( "https://duooomi.com/") as string; - export const authClient = createAuthClient({ - baseURL, + baseURL:"https://api.mixvideo.bowong.cc", }); diff --git a/src/lib/wechat.ts b/src/lib/wechat.ts index 8c0cd42..29fd106 100644 --- a/src/lib/wechat.ts +++ b/src/lib/wechat.ts @@ -1,5 +1,4 @@ import { authClient } from "@/lib/auth-client"; -import { getCurrentUrl } from "@/lib/url"; export const wechatSignIn = async () => { // Per Better Auth docs: WeChat uses the social provider flow. @@ -9,19 +8,3 @@ export const wechatSignIn = async () => { }); }; -// If you prefer Generic OAuth style, you can use this variant instead. -// (Requires your auth server to support the OAuth2 endpoint for providerId="wechat".) -export const wechatSignInOAuth2 = async () => { - // Note: Depending on your Better Auth client configuration (plugins), - // `signIn.oauth2` may not be present in types. - // This cast keeps the demo code working while still using your providerId="wechat". - const signInAny = authClient as unknown as { - signIn: { oauth2: (args: { providerId: string; callbackURL: string }) => Promise }; - }; - - return signInAny.signIn.oauth2({ - providerId: "wechat", - callbackURL: getCurrentUrl(), - }); -}; - diff --git a/src/pages/wechat-demo.tsx b/src/pages/wechat-demo.tsx index 6d655cd..a3395e8 100644 --- a/src/pages/wechat-demo.tsx +++ b/src/pages/wechat-demo.tsx @@ -1,13 +1,12 @@ -import { useState } from "react"; -import { wechatSignIn, wechatSignInOAuth2 } from "@/lib/wechat"; -import { getCurrentUrl } from "@/lib/url"; +import { useCallback, useState } from "react"; +import { wechatSignIn } from "@/lib/wechat"; const WechatDemo = () => { const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [result, setResult] = useState(null); - const start = async (fn: () => Promise) => { + const start = useCallback(async (fn: () => Promise) => { setLoading(true); setError(null); setResult(null); @@ -22,7 +21,7 @@ const WechatDemo = () => { } finally { setLoading(false); } - }; + }, []); return (
{

微信登录 Demo (Better Auth)

需要你本地/线上先启动 Better Auth Server,并在服务端配置 `socialProviders.wechat` - (`clientId/clientSecret`)。客户端再点击按钮触发登录跳转。 + (`clientId/clientSecret`)。点击下方按钮后才会发起微信登录跳转。

- -
-
当前 URL
-
-            {getCurrentUrl()}
-          
-
-
- -
diff --git a/vite.config.ts b/vite.config.ts index 702a56d..c3d5a0f 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -10,7 +10,17 @@ export default defineConfig({ }, }, server: { - allowedHosts: ["duooomi.com"] + allowedHosts: ["duooomi.com"], + proxy: { + // Avoid browser CORS by tunneling requests to the upstream API. + // `src/lib/auth-client.ts` uses baseURL `/mixvideo` in dev. + "/mixvideo": { + target: "https://api.mixvideo.bowong.cc", + changeOrigin: true, + secure: true, + rewrite: (path) => path.replace(/^\/mixvideo/, ""), + }, + }, }, preview: { allowedHosts: ["duooomi.com"]