-
Notifications
You must be signed in to change notification settings - Fork 116
/
Copy pathpage.tsx
69 lines (62 loc) · 2.2 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 { WorkOS } from '@workos-inc/node';
import type { User } from '@workos-inc/node';
import Link from 'next/link';
import { deleteUser } from './users-table';
// This example uses Next.js with React Server Components.
// Because this page is an RSC, the code stays on the server, which allows
// us to use the WorkOS Node SDK without exposing our API key to the client.
//
// If your application is a single page app (SPA), you will need to:
// - create a backend endpoint to return the list of users
// - adapt the code below in your endpoint
// - make an API call to your backend (e.g using `fetch`)
const workos = new WorkOS(process.env.WORKOS_API_KEY);
export default async function UsersTable({
searchParams,
}: {
searchParams: { before?: string; after?: string };
}) {
const users = await workos.userManagement.listUsers({ limit: 5, ...searchParams });
const { before, after } = users.listMetadata;
return (
<main>
<h1>Users</h1>
<table>
<thead>
<tr>
<th style={{ width: '40%' }}>Email</th>
<th>Name</th>
<th style={{ width: '10%', textAlign: 'center' }}>Verified</th>
<th style={{ width: '10%', textAlign: 'right' }} />
</tr>
</thead>
<tbody>
{users.data.map((user) => (
<tr key={user.id}>
<td title={user.id}>{user.email}</td>
<td>{formatName(user)}</td>
<td style={{ textAlign: 'center' }}>{user.emailVerified ? 'Yes' : 'No'}</td>
<td style={{ textAlign: 'right' }}>
<form action={deleteUser}>
<input type="hidden" name="userId" value={user.id} />
<button type="submit">Delete</button>
</form>
</td>
</tr>
))}
</tbody>
</table>
<nav>
{before ? <Link href={`?before=${before}`}>Previous</Link> : 'Previous'}
{after ? <Link href={`?after=${after}`}>Next</Link> : 'Next'}
</nav>
</main>
);
}
function formatName(user: User) {
if (user.firstName && user.lastName) {
return `${user.firstName} ${user.lastName}`;
} else {
return user.lastName ?? user.firstName ?? '';
}
}