forked from stack-auth/stack-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage.tsx
More file actions
76 lines (66 loc) · 1.95 KB
/
page.tsx
File metadata and controls
76 lines (66 loc) · 1.95 KB
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
70
71
72
73
74
75
76
import { stackServerApp } from "@/stack";
import { UserButton } from "@stackframe/stack";
import Link from "next/link";
import { Suspense } from "react";
export default function Home() {
return (
<main>
<h1>Welcome to Stack's Partial Prerendering demo!</h1>
<p>
This is a demo of Stack's partial prerendering capabilities. The text you are reading here is statically prerendered, while user information below is fetched on a dynamic server component.
</p>
<p>
For the demo, there is an artificial two second delay for network requests. Reload the page to see it again.
</p>
<div style={{ border: "1px solid grey", margin: 8, padding: 8, borderRadius: 4 }}>
<Suspense fallback="Loading user info...">
<UserInfo />
</Suspense>
</div>
<div style={{ marginTop: 96 }}>
Source code:
<pre>
{`
<Suspense fallback="Loading user info...">
<UserInfo />
</Suspense>
async function UserInfo() {
const user = await stackServerApp.getUser();
return (
<div>
{user && <>
You are logged in.<br />
Display name: {user.displayName}<br />
E-mail: {user.primaryEmail}<br />
<Link href="/handler/account-settings">Account settings</Link>
</>}
{!user && <>
You are not logged in.<br />
<Link href="/handler/sign-in">Log in</Link>
</>}
</div>
);
}
`.trim()}
</pre>
</div>
</main>
);
}
async function UserInfo() {
const user = await stackServerApp.getUser();
return (
<div>
{user && <>
You are logged in.<br />
Display name: {user.displayName ?? "None"}<br />
E-mail: {user.primaryEmail ?? "None"}<br />
<Link href="/handler/account-settings">Account settings</Link>
</>}
{!user && <>
You are not logged in.<br />
<Link href="/handler/sign-in">Log in</Link>
</>}
</div>
);
}