diff --git a/demo/nextjs/app/dashboard/user-card.tsx b/demo/nextjs/app/dashboard/user-card.tsx index 07186fbd..324c781f 100644 --- a/demo/nextjs/app/dashboard/user-card.tsx +++ b/demo/nextjs/app/dashboard/user-card.tsx @@ -24,7 +24,7 @@ import { import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { PasswordInput } from "@/components/ui/password-input"; -import { client, signOut, user, useSession } from "@/lib/auth-client"; +import { client, signOut, useSession } from "@/lib/auth-client"; import { Session } from "@/lib/auth-types"; import { MobileIcon } from "@radix-ui/react-icons"; import { @@ -180,7 +180,7 @@ export default function UserCard(props: { className="text-red-500 opacity-80 cursor-pointer text-xs border-muted-foreground border-red-600 underline " onClick={async () => { setIsTerminating(session.id); - const res = await client.user.revokeSession({ + const res = await client.revokeSession({ id: session.id, }); @@ -497,7 +497,7 @@ function ChangePassword() { return; } setLoading(true); - const res = await user.changePassword({ + const res = await client.changePassword({ newPassword: newPassword, currentPassword: currentPassword, revokeOtherSessions: signOutDevices, @@ -610,7 +610,7 @@ function EditUserDialog(props: { session: Session | null }) { disabled={isLoading} onClick={async () => { setIsLoading(true); - await user.update({ + await client.updateUser({ image: image ? await convertImageToBase64(image) : undefined, name: name ? name : undefined, fetchOptions: { diff --git a/demo/nextjs/lib/auth-client.ts b/demo/nextjs/lib/auth-client.ts index 6973862e..bc881960 100644 --- a/demo/nextjs/lib/auth-client.ts +++ b/demo/nextjs/lib/auth-client.ts @@ -33,7 +33,6 @@ export const { signIn, signOut, useSession, - user, organization, useListOrganizations, useActiveOrganization, diff --git a/docs/content/docs/concepts/session-management.mdx b/docs/content/docs/concepts/session-management.mdx index c8340679..1fe6bebb 100644 --- a/docs/content/docs/concepts/session-management.mdx +++ b/docs/content/docs/concepts/session-management.mdx @@ -64,7 +64,7 @@ The `listSessions` function returns a list of sessions that are active for the u ```ts title="client.ts" import { authClient } from "@/lib/client" -const sessions = await authClient.user.listSessions() +const sessions = await authClient.listSessions() ``` ### Revoke Session @@ -74,7 +74,7 @@ When a user signs out of a device, the session is automatically ended. However, To end a session, use the `revokeSession` function. Just pass the session ID as a parameter. ```ts title="client.ts" -await authClient.user.revokeSession({ +await authClient.revokeSession({ id: session.id, }) ``` @@ -84,7 +84,7 @@ await authClient.user.revokeSession({ To revoke all sessions, you can use the `revokeSessions` function. ```ts title="client.ts" -await authClient.user.revokeSessions() +await authClient.revokeSessions() ``` ### Revoking Sessions on Password Change @@ -92,7 +92,7 @@ await authClient.user.revokeSessions() You can revoke all sessions when the user changes their password by passing `revokeOtherSessions` true on `changePAssword` function. ```ts title="auth.ts" -await authClient.user.changePassword({ +await authClient.changePassword({ newPassword: newPassword, currentPassword: currentPassword, revokeOtherSessions: signOutDevices, diff --git a/docs/content/docs/concepts/users-accounts.mdx b/docs/content/docs/concepts/users-accounts.mdx index eb41bf26..7c3c780b 100644 --- a/docs/content/docs/concepts/users-accounts.mdx +++ b/docs/content/docs/concepts/users-accounts.mdx @@ -25,7 +25,7 @@ The user table can be extended by plugins to store additional data. When a plugi To update user information, you can use the `updateUser` function provided by the client. The `updateUser` function takes an object with the following properties: ```ts -await authClient.user.update({ +await authClient.updateUser({ image: "https://example.com/image.jpg", name: "John Doe", }) @@ -66,7 +66,7 @@ export const auth = betterAuth({ Once enabled, use the `changeEmail` function on the client to update a user’s email. The user must verify their current email before changing it. ```ts -await authClient.user.changeEmail({ +await authClient.changeEmail({ newEmail: "new-email@email.com", callbackURL: "/dashboard", //to redirect after verification }); @@ -83,7 +83,7 @@ After verification, the new email is updated in the user table, and a confirmati Password of a user isn't stored in the user table. Instead, it's stored in the account table. To change the password of a user, you can use the `changePassword` function provided by the client. The `changePassword` function takes an object with the following properties: ```ts -await authClient.user.changePassword({ +await authClient.changePassword({ newPassword: "newPassword123", currentPassword: "oldPassword123", revokeOtherSessions: true, // revoke all other sessions the user is signed into @@ -95,7 +95,7 @@ await authClient.user.changePassword({ If a user was registered using oAuth or other providers, they won't have a password. In this case, you can use the `setPassword` function to set a password for the user. This will create a new credential account with the password. ```ts -await authClient.user.setPassword({ +await authClient.setPassword({ password, }); ``` @@ -125,7 +125,7 @@ The account table stores the authentication data of the user. The account table To list user accounts you can use `client.user.listAccounts` method. Which will return all accounts associated with a user. ```ts -const accounts = await authClient.user.listAccounts(); +const accounts = await authClient.listAccounts(); ``` ### Account Linking @@ -165,7 +165,7 @@ Users already signed in can manually link their account to additional social pro - **Linking Social Accounts:** Use the `user.linkSocial` method on the client to link a social provider to the user's account. ```ts - await client.user.linkSocial({ + await client.linkSocial({ provider: "google", // Provider to link callbackURL: "/callback" // Callback URL after linking completes }); diff --git a/docs/content/docs/plugins/bearer.mdx b/docs/content/docs/plugins/bearer.mdx index 5e5392a5..eedf90b5 100644 --- a/docs/content/docs/plugins/bearer.mdx +++ b/docs/content/docs/plugins/bearer.mdx @@ -58,7 +58,7 @@ Now you can make authenticated API calls: ```ts title="client.ts" // This request is automatically authenticated -const { data } = await authClient.user.listSessions(); +const { data } = await authClient.listSessions(); ``` ### 4. Per-Request Token (Optional) @@ -66,7 +66,7 @@ const { data } = await authClient.user.listSessions(); You can also provide the token for individual requests: ```ts title="client.ts" -const { data } = await authClient.user.listSessions({ +const { data } = await authClient.listSessions({ fetchOptions: { headers: { Authorization: `Bearer ${token}` diff --git a/examples/astro-example/src/components/user-card.tsx b/examples/astro-example/src/components/user-card.tsx index d999a2f4..d91138b8 100644 --- a/examples/astro-example/src/components/user-card.tsx +++ b/examples/astro-example/src/components/user-card.tsx @@ -3,16 +3,11 @@ import { signOut, twoFactorActions, useListPasskeys, - userActions, useSession, + revokeSession, + updateUser, } from "@/libs/auth-client"; -import { - Card, - CardContent, - CardDescription, - CardHeader, - CardTitle, -} from "./ui/card"; +import { Card, CardContent, CardHeader, CardTitle } from "./ui/card"; import { UAParser } from "ua-parser-js"; import { Image, ImageFallback, ImageRoot } from "./ui/image"; import type { Session, User } from "better-auth/types"; @@ -109,7 +104,7 @@ export function UserCard(props: {