2022-03-21 22:15:24 -05:00
|
|
|
|
---
|
|
|
|
|
title: 登录
|
|
|
|
|
subtitle: 2 steps
|
|
|
|
|
---
|
|
|
|
|
## Step 1: Setup your login
|
|
|
|
|
|
|
|
|
|
The Logto React SDK provides you tools and hooks to quickly implement your own authorization flow. First, let’s enter your redirect URI
|
|
|
|
|
|
2022-04-06 02:41:29 -05:00
|
|
|
|
```redirectUris
|
2022-03-21 22:15:24 -05:00
|
|
|
|
Redirect URI
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Add the following code to your web app
|
|
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
|
import React from "react";
|
|
|
|
|
import { useLogto } from '@logto/react';
|
|
|
|
|
|
|
|
|
|
const SignInButton = () => {
|
|
|
|
|
const { signIn } = useLogto();
|
|
|
|
|
const redirectUrl = window.location.origin + '/callback';
|
|
|
|
|
|
|
|
|
|
return <button onClick={() => signIn(redirectUrl)}>Sign In</button>;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default SignInButton;
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Step 2: Retrieve Auth Status
|
|
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
|
import React from "react";
|
|
|
|
|
import { useLogto } from '@logto/react';
|
|
|
|
|
|
|
|
|
|
const App = () => {
|
|
|
|
|
const { isAuthenticated, signIn } = useLogto();
|
|
|
|
|
|
|
|
|
|
if !(isAuthenticated) {
|
|
|
|
|
return <SignInButton />
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <>
|
|
|
|
|
<AppContent />
|
|
|
|
|
<SignOutButton />
|
|
|
|
|
</>
|
|
|
|
|
};
|
|
|
|
|
```
|