2025-07-28 07:50:50 +08:00
|
|
|
import { createAuthClient } from "better-auth/client";
|
|
|
|
|
import {
|
|
|
|
|
organizationClient,
|
|
|
|
|
oidcClient,
|
|
|
|
|
genericOAuthClient,
|
2025-07-28 10:32:25 +08:00
|
|
|
usernameClient,
|
2025-07-28 07:50:50 +08:00
|
|
|
} from "better-auth/client/plugins";
|
|
|
|
|
import { ssoClient } from "@better-auth/sso/client";
|
|
|
|
|
|
|
|
|
|
import { toast } from "@nice/ui/components/sonner";
|
|
|
|
|
|
2025-07-28 10:32:25 +08:00
|
|
|
export const client = createAuthClient({
|
2025-07-28 07:50:50 +08:00
|
|
|
baseURL: process.env.NEXT_PUBLIC_API_URL, // 可以通过环境变量配置
|
|
|
|
|
plugins: [
|
|
|
|
|
organizationClient(),
|
|
|
|
|
oidcClient(),
|
|
|
|
|
genericOAuthClient(),
|
|
|
|
|
ssoClient(),
|
2025-07-28 10:32:25 +08:00
|
|
|
usernameClient()
|
2025-07-28 07:50:50 +08:00
|
|
|
],
|
|
|
|
|
fetchOptions: {
|
|
|
|
|
onError(e) {
|
|
|
|
|
if (e.error.status === 429) {
|
|
|
|
|
toast.error("Too many requests. Please try again later.");
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const {
|
|
|
|
|
signUp,
|
|
|
|
|
signIn,
|
|
|
|
|
signOut,
|
|
|
|
|
useSession,
|
|
|
|
|
organization,
|
|
|
|
|
useListOrganizations,
|
|
|
|
|
useActiveOrganization,
|
2025-07-28 10:32:25 +08:00
|
|
|
} = client;
|