From e5cfa6748caacd3e05a78c19350d8b7b5e57200f Mon Sep 17 00:00:00 2001 From: Bereket Engida Date: Sun, 13 Oct 2024 21:40:46 +0300 Subject: [PATCH] docs: move client to authClient --- .../docs/authentication/email-password.mdx | 46 +++++++++---------- docs/content/docs/reference/security.mdx | 2 +- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/docs/content/docs/authentication/email-password.mdx b/docs/content/docs/authentication/email-password.mdx index 6abec65648..64a99aec3f 100644 --- a/docs/content/docs/authentication/email-password.mdx +++ b/docs/content/docs/authentication/email-password.mdx @@ -42,15 +42,13 @@ To signup a user, you can use the `signUp.email` function provided by the client - `dontRememberMe`: If true, the user will be signed out when the browser session is closed. (optional) ```ts title="client.ts" -const signup = async () => { - const data = await client.signUp.email({ - email: "test@example.com", - password: "password1234", - name: "test", - image: "https://example.com/image.png", - callbackURL: "/" - }) -} +const { data, error } = await authClient.signUp.email({ + email: "test@example.com", + password: "password1234", + name: "test", + image: "https://example.com/image.png", + callbackURL: "/" +}) ``` ### Signin @@ -63,17 +61,19 @@ To signin a user, you can use the `signIn.email` function provided by the client - `dontRememberMe`: If true, the user will be signed out when the browser is closed. (optional) ```ts title="client.ts" -import { createAuthClient } from "better-auth/client" - -const client = createAuthClient() - -const signin = async () => { - const data = await client.signIn.email({ +const { data, error } = await authClient.signIn.email({ email: "test@example.com", password: "password1234", callbackURL: "/" - }) -} +}) +``` + +### Signout + +To signout a user, you can use the `signOut` function provided by the client. + +```ts title="client.ts" +await client.signOut() ``` ### Email Verification @@ -130,12 +130,10 @@ It takes an object with the following properties: - `redirectTo`: The URL to redirect to after the user clicks on the link in the email. If the token is valid, the user will be redirected to this URL with the token in the query string. If the token is invalid, the user will be redirected to this URL with an error message in the query string `?error=invalid_token`. ```ts title="client.ts" -const forgetPassword = async () => { - const data = await client.forgetPassword({ - email: "test@example.com", - redirectTo: "/reset-password" - }) -} +const { data, error } = await client.forgetPassword({ + email: "test@example.com", + redirectTo: "/reset-password" +}) ``` When user click on the link in the email he will be redirected to the reset password page. You can add the reset password page to your app. Then you can use `resetPassword` function to reset the password. It takes an object with the following properties: @@ -143,7 +141,7 @@ When user click on the link in the email he will be redirected to the reset pass - `newPassword`: The new password of the user. ```ts title="client.ts" -const data = await client.resetPassword({ +const { data, error } = await client.resetPassword({ newPassword: "password1234", }) ``` diff --git a/docs/content/docs/reference/security.mdx b/docs/content/docs/reference/security.mdx index a705fb1306..187b154e33 100644 --- a/docs/content/docs/reference/security.mdx +++ b/docs/content/docs/reference/security.mdx @@ -7,4 +7,4 @@ This page contains information about security features of Better Auth. ## Reporting Vulnerabilities -If you have found a security vulnerability in Better Auth, please report it to us at [security@better-auth.com](mailto:security@betterstack.com). All reports will be promptly addressed, and you'll be credited accordingly. \ No newline at end of file +If you have found a security vulnerability in Better Auth, please report it to us at [security@better-auth.com](mailto:security@betterstack.com). All reports will be promptly addressed, and you'll be credited accordingly. \ No newline at end of file