-
Notifications
You must be signed in to change notification settings - Fork 114
/
Copy pathpage.tsx
32 lines (29 loc) · 888 Bytes
/
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
import { getSignInUrl, getUser, signOut } from '@workos-inc/authkit-nextjs';
export default async function WithNextjs() {
// Retrieves the user from the session or returns `null` if no user is signed in
const { user } = await getUser();
// Get the URL to redirect the user to AuthKit to sign in
const signInUrl = await getSignInUrl();
return (
<main>
<h1>Using hosted AuthKit</h1>
<h2>With Next.js library</h2>
{user ? (
<>
<p>Welcome back {user?.firstName && `, ${user?.firstName}`}</p>
<form
action={async () => {
'use server';
await signOut();
}}
>
<button type="submit">Sign out</button>
</form>
</>
) : (
<a href={signInUrl}>Sign in</a>
)}
<pre>{JSON.stringify(user, null, 2)}</pre>
</main>
);
}