diff --git a/packages/console/src/assets/docs/tutorial/integrate-sdk/react.mdx b/packages/console/src/assets/docs/tutorial/integrate-sdk/react.mdx
index 411147a75..0d7ddbf77 100644
--- a/packages/console/src/assets/docs/tutorial/integrate-sdk/react.mdx
+++ b/packages/console/src/assets/docs/tutorial/integrate-sdk/react.mdx
@@ -2,9 +2,10 @@ import UriInputField from '@mdx/components/UriInputField';
import Step from '@mdx/components/Step';
import Tabs from '@mdx/components/Tabs';
import TabItem from '@mdx/components/TabItem';
+import Alert from '@/components/Alert';
-
-
-```html
-
-```
-
-
-
-
-```bash
-git clone https://github.com/logto-io/js.git
-pnpm build
-```
-
props.onNext(2)}
>
-Add the following code to your main html file. You may need client ID and authorization domain.
+Import and use `LogtoProvider` to provide a Logto context:
@@ -99,54 +67,74 @@ const App = () => {
props.onNext(3)}
>
-### Step 1: Setup your login
+
+ In the following steps, we assume your app is running on http://localhost:1234.
+
-The Logto React SDK provides you tools and hooks to quickly implement your own authorization flow. First, let’s enter your redirect URI
+### Configure Redirect URI
+
+First, let’s enter your redirect URI. E.g. `http://localhost:1234/callback`.
-Add the following code to your web app
+### Implement a sign-in button
+
+We provide two hooks `useHandleSignInCallback()` and `useLogto()` which can help you easily manage the authentication flow.
+
+Go back to your IDE/editor, use the following code to implement the sign-in button:
```tsx
-import React from 'react';
import { useLogto } from '@logto/react';
-const SignInButton = () => {
- const { signIn } = useLogto();
- const redirectUrl = window.location.origin + '/callback';
+const SignIn = () => {
+ const { signIn, isAuthenticated } = useLogto();
- return ;
-};
-
-export default SignInButton;
-```
-
-### Step 2: Retrieve Auth Status
-
-```tsx
-import React from "react";
-import { useLogto } from '@logto/react';
-
-const App = () => {
- const { isAuthenticated, signIn } = useLogto();
-
- if !(isAuthenticated) {
- return
+ if (isAuthenticated) {
+ return
Signed in
;
}
- return <>
-
-
- >
+ return (
+
+ );
};
```
+### Handle redirect
+
+We're almost there! In the last step, we use `http://localhost:1234/callback` as the Redirect URI, and now we need to handle it properly.
+
+First let's create a callback component:
+
+```tsx
+import { useHandleSignInCallback } from '@logto/react';
+
+const Callback = () => {
+ const { isLoading } = useHandleSignInCallback(() => {
+ // Navigate to root path when finished
+ });
+
+ // When it's working in progress
+ if (isLoading) {
+ return
Redirecting...
;
+ }
+};
+```
+
+Finally insert the code below to create a `/callback` route which does NOT require authentication:
+
+```tsx
+// Assuming react-router
+} />
+```
+
{
onButtonClick={() => props.onNext(4)}
>
-Execute signOut() methods will redirect users to the Logto sign out page. After a success sign out, all use session data and auth status will be cleared.
+Calling `.signOut()` will clear all the Logto data in memory and localStorage if they exist.
+
+After signing out, it'll be great to redirect user back to your website. Let's add `http://localhost:1234` as the Post Sign-out URI below, and use it as the parameter when calling `.signOut()`.
-Add the following code to your web app
+### Implement a sign-out button
```tsx
-import React from 'react';
-import { useLogto } from '@logto/react';
-
-const SignOutButton = () => {
+const SignOut = () => {
const { signOut } = useLogto();
- return ;
+ return (
+
+ );
};
-
-export default SignOutButton;
```
-- [SDK Documentation](https://link-url-here.org)
-- [OIDC Documentation](https://link-url-here.org)
-- [Calling API to fetch accessToken](https://link-url-here.org)
+- [Customize sign-in experience](https://docs.logto.io/docs/recipes/customize-sie)
+- [Enable SMS or email passcode sign-in](https://docs.logto.io/docs/tutorials/get-started/enable-passcode-sign-in)
+- [Enable social sign-in](https://docs.logto.io/docs/tutorials/get-started/enable-social-sign-in)
+- [Protect your API](https://docs.logto.io/docs/recipes/protect-your-api)
diff --git a/packages/console/src/assets/docs/tutorial/integrate-sdk/react_zh-cn.mdx b/packages/console/src/assets/docs/tutorial/integrate-sdk/react_zh-cn.mdx
index 4405b40ff..a2b1624a5 100644
--- a/packages/console/src/assets/docs/tutorial/integrate-sdk/react_zh-cn.mdx
+++ b/packages/console/src/assets/docs/tutorial/integrate-sdk/react_zh-cn.mdx
@@ -2,10 +2,11 @@ import UriInputField from '@mdx/components/UriInputField';
import Step from '@mdx/components/Step';
import Tabs from '@mdx/components/Tabs';
import TabItem from '@mdx/components/TabItem';
+import Alert from '@/components/Alert';
props.onNext(1)}
@@ -31,156 +32,144 @@ yarn add @logto/react
pnpm add @logto/react
```
-
-
-
-```html
-
-```
-
-
-
-
-```bash
-git clone https://github.com/logto-io/js.git
-pnpm build
-```
-
props.onNext(2)}
>
-在项目的 App.tsx 文件中,加入如下代码(需提前准备好 client ID 以及 authorization domain)
+Import 并使用 `LogtoProvider` 来提供 Logto context: