This commit is contained in:
2026-04-16 18:43:45 +08:00
parent 194f15d954
commit d02c578440
4 changed files with 18 additions and 60 deletions

View File

@@ -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",
});

View File

@@ -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<unknown> };
};
return signInAny.signIn.oauth2({
providerId: "wechat",
callbackURL: getCurrentUrl(),
});
};

View File

@@ -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<string | null>(null);
const [result, setResult] = useState<string | null>(null);
const start = async (fn: () => Promise<unknown>) => {
const start = useCallback(async (fn: () => Promise<unknown>) => {
setLoading(true);
setError(null);
setResult(null);
@@ -22,7 +21,7 @@ const WechatDemo = () => {
} finally {
setLoading(false);
}
};
}, []);
return (
<div
@@ -48,25 +47,8 @@ const WechatDemo = () => {
<h1 style={{ margin: "0 0 8px" }}> Demo (Better Auth)</h1>
<p style={{ margin: "0 0 16px", color: "#444" }}>
/线 Better Auth Server `socialProviders.wechat`
`clientId/clientSecret`
`clientId/clientSecret`
</p>
<div style={{ marginBottom: 16 }}>
<div style={{ fontSize: 13, color: "#555", marginBottom: 8 }}> URL</div>
<pre
style={{
margin: 0,
padding: 12,
background: "#f3f3f3",
borderRadius: 8,
overflow: "auto",
color: "#222",
}}
>
{getCurrentUrl()}
</pre>
</div>
<div style={{ display: "flex", gap: 12, flexWrap: "wrap" }}>
<button
onClick={() => start(wechatSignIn)}
@@ -80,22 +62,7 @@ const WechatDemo = () => {
cursor: "pointer",
}}
>
social
</button>
<button
onClick={() => start(wechatSignInOAuth2)}
disabled={loading}
style={{
padding: "10px 14px",
borderRadius: 8,
border: "1px solid #999",
background: "#fff",
color: "#111",
cursor: "pointer",
}}
>
oauth2
</button>
</div>

View File

@@ -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"]