Skip to content

Commit cff98a6

Browse files
committed
refactor: add sequence diagrams to illustrate sign-in flows
1 parent 966a893 commit cff98a6

File tree

2 files changed

+87
-3
lines changed

2 files changed

+87
-3
lines changed

docs/docs/references/using-cli/custom-ui-local-proxy.mdx

Lines changed: 81 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,70 @@ import Tabs from '@theme/Tabs';
66

77
<Availability cloud oss={{ major: 1, minor: 19 }} />
88

9-
For Cloud users, We've made it easy to let you "Bring your own UI" to Logto. Cloud users can now upload a zip file containing the custom UI assets in Logto Console -> Sign-in experience -> Custom UI. (Check out the [Bring your UI](/docs/recipes/customize-sie/bring-your-ui) for more details.)
9+
For Logto Cloud users, We've made it easy to let you "Bring your own UI" to Logto. Cloud users can now upload a zip file containing the custom UI assets in Logto Console -> Sign-in experience -> Custom UI. (Check out the [Bring your UI](/docs/recipes/customize-sie/bring-your-ui) page for more details.)
1010

1111
However, when developing such custom UI pages, users want to test and debug the code locally, before uploading to Logto Cloud. This CLI command helps you set up a local proxy and connect the following 3 entities together:
1212
your Logto cloud auth endpoint, your application, and your custom sign-in UI.
1313

14-
Assuming your Cloud tenant ID is `foobar`, and you have a custom sign-in page running on dev server at `http://localhost:4000`.
14+
## Why do I need this?
15+
16+
By default, when you click the "sign-in" button in your application, you will be navigated to the sign-in page configured at Logto endpoint. A successful sign-in flow can be illustrated as follows:
17+
18+
```mermaid
19+
sequenceDiagram
20+
box Local machine
21+
participant A as Your application
22+
end
23+
box Logto Cloud
24+
participant B as Logto Cloud auth endpoint
25+
participant C as Logto sign-in page
26+
end
27+
A ->> B: User initiates "sign-in" action and request auth
28+
B -->> A: Return auth response and tell the client<br/>to redirect to the Logto sign-in page
29+
A ->> C: Redirect to the Logto sign-in page
30+
C ->> B: Submit the sign-in form and<br/>request experience API to authenticate
31+
B -->> C: Respond the sign-in request and<br/>tell the client to redirect to your application
32+
C -->> A: Redirect to your application
33+
A --> A: Handle the sign-in callback and<br/>the user is now authenticated
34+
```
35+
36+
But now since you are developing your own custom sign-in UI, you need a way to navigate to the custom sign-in UI pages running on your local machine instead.
37+
This requires a local proxy to intercept the outgoing requests from your application and redirect them to your custom sign-in UI pages.
38+
39+
Additionally, you need to interact with Logto's experience API to authenticate users and manage sessions.
40+
This proxy will also help forward these experience API requests to Logto Cloud in order to avoid CORS issues.
41+
42+
The sequence diagram below illustrates how a successful "sign-in" flow works with your custom UI and the proxy in place:
43+
44+
```mermaid
45+
sequenceDiagram
46+
box Local machine
47+
participant A as Your application
48+
participant B as Your custom sign-in UI
49+
participant C as proxy
50+
end
51+
box Logto Cloud
52+
participant D as Logto Cloud auth endpoint
53+
participant E as Logto sign-in page
54+
end
55+
A ->> C: User initiates "sign-in" action and request auth
56+
C ->> D: Forward auth request to Logto Cloud endpoint
57+
D -->> C: Return auth response andtell the client<br/>to redirect to the Logto sign-in page
58+
C ->> B: Intercept the redirect and<br/>redirect to your custom sign-in page
59+
B ->> C: Submit the sign-in form and<br/>request experience API to authenticate
60+
C ->> D: Forward the experience API requests to Logto Cloud
61+
D -->> C: Authenticate sign-in request and<br/>tell the client to redirect to your application
62+
C -->> A: Redirect to your application
63+
A --> A: Handle the sign-in callback and<br/>the user is now authenticated
64+
```
65+
66+
With the proxy in place, you can now develop and test your custom sign-in UI locally, without needing to upload the assets to Logto Cloud every time you make a change.
67+
68+
## Instructions
69+
70+
### Step 1: Execute the command
71+
72+
Assuming your Cloud tenant ID is `foobar`, and you have a custom sign-in page running on your local dev server at `http://localhost:4000`.
1573

1674
Then you can execute the command this way:
1775

@@ -34,7 +92,7 @@ npx @logto/cli proxy -p 9000 --experience-uri http://localhost:4000/ --endpoint
3492

3593
</Tabs>
3694

37-
It also works well if you have custom domain configured in Logto:
95+
It also works if you have custom domain configured in Logto:
3896

3997
<Tabs groupId="cmd">
4098

@@ -76,8 +134,28 @@ npx @logto/cli proxy -p 9000 --experience-path /path/to/your/static/files --endp
76134

77135
</Tabs>
78136

137+
### Step 2: Update endpoint URI in your application
138+
79139
Finally, run your application and set its Logto endpoint to the proxy address `http://localhost:9000/` instead.
80140

141+
Let's take a React application as an example:
142+
143+
```tsx title=App.tsx
144+
import { LogtoProvider, LogtoConfig } from '@logto/react';
145+
146+
const config: LogtoConfig = {
147+
// endpoint: 'https://foobar.logto.app/', // original Logto Cloud endpoint
148+
endpoint: 'http://localhost:9000/', // proxy address
149+
appId: '<your-application-id>',
150+
};
151+
152+
const App = () => (
153+
<LogtoProvider config={config}>
154+
<YourAppContent />
155+
</LogtoProvider>
156+
);
157+
```
158+
81159
If all set up correctly, when you click the "sign-in" button in your application, you should be navigated to your custom sign-in page instead of Logto's built-in UI, along with valid session (cookies) that allows you to further interact with Logto experience API.
82160

83161
Happy coding!

src/scss/custom.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,3 +301,9 @@ hr {
301301
code {
302302
tab-size: 4;
303303
}
304+
305+
svg[id^='mermaid-'] {
306+
rect[class='rect'] {
307+
stroke: var(--logto-border);
308+
}
309+
}

0 commit comments

Comments
 (0)