Skip to content

Commit 95635d9

Browse files
committed
docs: add clerk sample for app router; upgrade docusaurus to 3.4
1 parent 8d1f556 commit 95635d9

File tree

5 files changed

+1023
-535
lines changed

5 files changed

+1023
-535
lines changed

docs/guides/authentication/clerk.md

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ sidebar_position: 2
44
sidebar_label: Clerk
55
---
66

7+
import Tabs from '@theme/Tabs';
8+
import TabItem from '@theme/TabItem';
9+
710
# Integrating With Clerk
811

912
[Clerk](https://clerk.com/) is a comprehensive authentication and user management platform, providing both APIs and pre-made UI components.
@@ -50,20 +53,45 @@ You can create an enhanced Prisma client that automatically validates access pol
5053

5154
To create such a client with a standard setup, call the `enhance` API with a regular Prisma client and the current user (fetched from Clerk). Here's an example:
5255

56+
<Tabs>
57+
58+
<TabItem value="app-router" label="Next.js App Router">
59+
60+
```ts
61+
import { enhance } from '@zenstackhq/runtime';
62+
import { auth } from "@clerk/nextjs/server";
63+
import { prisma } from '../lib/db';
64+
65+
async function getPrisma() {
66+
const authObject = auth();
67+
// create a wrapper of Prisma client that enforces access policy
68+
return enhance(prisma, {
69+
user: authObject ? { id: authObject.userId } : undefined,
70+
});
71+
}
72+
```
73+
74+
</TabItem>
75+
76+
<TabItem value="react" label="Next.js Pages Router">
77+
5378
```ts
5479
import type { NextApiRequest } from 'next';
5580
import { enhance } from '@zenstackhq/runtime';
5681
import { getAuth } from '@clerk/nextjs/server';
5782
import { prisma } from '../lib/db';
5883

5984
async function getPrisma(req: NextApiRequest) {
60-
const auth = getAuth(req);
61-
// create a wrapper of Prisma client that enforces access policy,
62-
// data validation, and @password, @omit behaviors
63-
return enhance(prisma, { user: auth ? { id: auth.userId } : undefined });
85+
const auth = getAuth(req);
86+
// create a wrapper of Prisma client that enforces access policy
87+
return enhance(prisma, { user: auth ? { id: auth.userId } : undefined });
6488
}
6589
```
6690

91+
</TabItem>
92+
93+
</Tabs>
94+
6795
---
6896

69-
You can find a working sample project [here](https://github.com/zenstackhq/docs-tutorial-clerk).
97+
You can find a working sample project for Next.js [here](https://github.com/zenstackhq/docs-tutorial-clerk). Use the "main" branch for app router, and the "pages-router" branch for pages router.

docs/quick-start/nextjs-app-router.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Next.js (app router)
33
description: Step-by-step guide for building a blogging app with Next.js (app router).
4-
sidebar_position: 2
4+
sidebar_position: 1
55
---
66

77
import Requirements from './_requirements.md';

docs/quick-start/nextjs.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Next.js (pages router)
33
description: Step-by-step guide for building a blogging app with Next.js (pages router).
4-
sidebar_position: 1
4+
sidebar_position: 2
55
---
66

77
import Requirements from './_requirements.md';

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
},
1717
"dependencies": {
1818
"@algolia/client-search": "^4.22.1",
19-
"@docusaurus/core": "3.2.1",
20-
"@docusaurus/preset-classic": "3.2.1",
21-
"@docusaurus/theme-common": "3.2.1",
22-
"@docusaurus/theme-mermaid": "3.2.1",
19+
"@docusaurus/core": "3.4.0",
20+
"@docusaurus/preset-classic": "3.4.0",
21+
"@docusaurus/theme-common": "3.4.0",
22+
"@docusaurus/theme-mermaid": "3.4.0",
2323
"@giscus/react": "^2.4.0",
2424
"@mdx-js/react": "^3.0.1",
2525
"autoprefixer": "^10.4.13",
@@ -35,8 +35,8 @@
3535
"tailwindcss": "^3.2.4"
3636
},
3737
"devDependencies": {
38-
"@docusaurus/module-type-aliases": "3.2.1",
39-
"@docusaurus/types": "^3.2.1",
38+
"@docusaurus/module-type-aliases": "3.4.0",
39+
"@docusaurus/types": "^3.4.0",
4040
"@tailwindcss/typography": "^0.5.9",
4141
"@tsconfig/docusaurus": "^2.0.3",
4242
"@types/node": "^20.11.17",

0 commit comments

Comments
 (0)