-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
page.tsx
69 lines (65 loc) 路 1.88 KB
/
page.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { getLogtoContext, getOrganizationTokens, signIn, signOut } from '@logto/next/server-actions';
import SignIn from './sign-in';
import SignOut from './sign-out';
import { logtoConfig } from './logto';
export default async function Home() {
const { isAuthenticated, claims } = await getLogtoContext(logtoConfig);
// If you need access token, pass the getAccessToken option.
// and you can pass the access token to other API server or pass down to a client component.
// const { isAuthenticated, claims, accessToken } = await getLogtoContext({ getAccessToken: true });
// console.log(accessToken);
const organizations = await getOrganizationTokens(logtoConfig);
return (
<main>
<h1>Hello Logto.</h1>
<div>
{isAuthenticated ? (
<SignOut
onSignOut={async () => {
'use server';
await signOut(logtoConfig);
}}
/>
) : (
<SignIn
onSignIn={async () => {
'use server';
await signIn(logtoConfig);
}}
/>
)}
</div>
{claims && (
<div>
<h2>Claims:</h2>
<table>
<thead>
<tr>
<th>Name</th>
<th>Value</th>
</tr>
</thead>
<tbody>
{Object.entries(claims).map(([key, value]) => (
<tr key={key}>
<td>{key}</td>
<td>{String(value)}</td>
</tr>
))}
</tbody>
</table>
</div>
)}
{organizations.length > 0 ? (
<div>
<h2>Organizations</h2>
<ul>
{organizations.map((organization) => (
<li key={organization.id}>{organization.id}</li>
))}
</ul>
</div>
) : null}
</main>
);
}