Skip to content

Commit bc6c028

Browse files
clerk example project updated (#8278)
1 parent 63d6b80 commit bc6c028

File tree

17 files changed

+107
-139
lines changed

17 files changed

+107
-139
lines changed

orm/clerk-nextjs/.gitignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@
2121
/build
2222

2323
# misc
24-
**/generated/prisma
2524
.DS_Store
2625
*.pem
27-
prisma/dev.db*
2826

2927
# debug
3028
npm-debug.log*
@@ -43,5 +41,4 @@ yarn-error.log*
4341
*.tsbuildinfo
4442
next-env.d.ts
4543

46-
# clerk configuration (can include secrets)
47-
/.clerk/
44+
/app/generated/prisma

orm/clerk-nextjs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ This example uses a [Prisma Postgres](https://prisma.io/postgres) database by de
4343

4444
1. Set up a new Prisma Postgres instance in the [Prisma Data Platform Console](https://console.prisma.io) and copy the database connection URL.
4545
2. Add your database url to the `.env`
46+
3. Run `npx prisma migrate dev --name init`
4647

4748
That's it, your project is now configured to use Prisma Postgres!
4849

File renamed without changes.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { verifyWebhook } from '@clerk/nextjs/webhooks'
2+
import { NextRequest } from 'next/server'
3+
import prisma from '@/lib/prisma'
4+
5+
export async function POST(req: NextRequest) {
6+
try {
7+
const evt = await verifyWebhook(req)
8+
const { id } = evt.data
9+
const eventType = evt.type
10+
console.log(`Received webhook with ID ${id} and event type of ${eventType}`)
11+
12+
if (eventType === 'user.created') {
13+
const { id, email_addresses, first_name, last_name } = evt.data
14+
await prisma.user.upsert({
15+
where: { clerkId: id },
16+
update: {},
17+
create: {
18+
clerkId: id,
19+
email: email_addresses[0].email_address,
20+
name: `${first_name} ${last_name}`,
21+
},
22+
})
23+
}
24+
25+
return new Response('Webhook received', { status: 200 })
26+
} catch (err) {
27+
console.error('Error verifying webhook:', err)
28+
return new Response('Error verifying webhook', { status: 400 })
29+
}
30+
}
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
'use client'
1+
"use client";
22

3-
import { useState } from 'react'
3+
import { useState } from "react";
44

55
export default function PostInputs() {
6-
const [title, setTitle] = useState('')
7-
const [content, setContent] = useState('')
6+
const [title, setTitle] = useState("");
7+
const [content, setContent] = useState("");
88

99
async function createPost(e: React.FormEvent) {
10-
e.preventDefault()
11-
if (!title || !content) return
10+
e.preventDefault();
11+
if (!title || !content) return;
1212

13-
await fetch('/api/posts', {
14-
method: 'POST',
15-
headers: { 'Content-Type': 'application/json' },
13+
await fetch("/api/posts", {
14+
method: "POST",
15+
headers: { "Content-Type": "application/json" },
1616
body: JSON.stringify({ title, content }),
17-
})
17+
});
1818

19-
setTitle('')
20-
setContent('')
21-
location.reload()
19+
setTitle("");
20+
setContent("");
21+
location.reload();
2222
}
2323

2424
return (
@@ -40,5 +40,5 @@ export default function PostInputs() {
4040
Post
4141
</button>
4242
</form>
43-
)
44-
}
43+
);
44+
}
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,46 @@
1-
import type { Metadata } from 'next'
2-
import { Geist, Geist_Mono } from 'next/font/google'
3-
import './globals.css'
1+
import type { Metadata } from "next";
2+
import { Geist, Geist_Mono } from "next/font/google";
3+
import "./globals.css";
44
import {
55
ClerkProvider,
66
UserButton,
77
SignInButton,
88
SignUpButton,
99
SignedOut,
1010
SignedIn,
11-
} from '@clerk/nextjs'
11+
} from "@clerk/nextjs";
1212

1313
const geistSans = Geist({
14-
variable: '--font-geist-sans',
15-
subsets: ['latin'],
16-
})
14+
variable: "--font-geist-sans",
15+
subsets: ["latin"],
16+
});
1717

1818
const geistMono = Geist_Mono({
19-
variable: '--font-geist-mono',
20-
subsets: ['latin'],
21-
})
19+
variable: "--font-geist-mono",
20+
subsets: ["latin"],
21+
});
2222

2323
export const metadata: Metadata = {
24-
title: 'Create Next App',
25-
description: 'Generated by create next app',
26-
}
24+
title: "Create Next App",
25+
description: "Generated by create next app",
26+
};
2727

2828
export default function RootLayout({
2929
children,
3030
}: Readonly<{
31-
children: React.ReactNode
31+
children: React.ReactNode;
3232
}>) {
3333
return (
3434
<ClerkProvider>
3535
<html lang="en">
3636
<body
37-
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
38-
>
37+
className={`${geistSans.variable} ${geistMono.variable} antialiased`}>
3938
<Navbar />
4039
{children}
4140
</body>
4241
</html>
4342
</ClerkProvider>
44-
)
43+
);
4544
}
4645

4746
const Navbar = () => {
@@ -55,5 +54,5 @@ const Navbar = () => {
5554
<UserButton />
5655
</SignedIn>
5756
</header>
58-
)
59-
}
57+
);
58+
};
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { currentUser } from '@clerk/nextjs/server'
2-
import prisma from '@/lib/prisma'
3-
import PostInputs from './components/PostInputs'
1+
import { currentUser } from "@clerk/nextjs/server";
2+
import prisma from "@/lib/prisma";
3+
import PostInputs from "@/app/components/PostInputs";
44

55
export default async function Home() {
6-
const user = await currentUser()
7-
if (!user) return <div className="flex justify-center">Sign in to post</div>
6+
const user = await currentUser();
7+
if (!user) return <div className="flex justify-center">Sign in to post</div>;
88

99
const posts = await prisma.post.findMany({
1010
where: { author: { clerkId: user.id } },
11-
orderBy: { createdAt: 'desc' },
12-
})
11+
orderBy: { createdAt: "desc" },
12+
});
1313

1414
return (
1515
<main className="max-w-2xl mx-auto p-4">
@@ -18,13 +18,12 @@ export default async function Home() {
1818
{posts.map((post) => (
1919
<div
2020
key={post.id}
21-
className="p-4 border border-zinc-800 rounded mt-4"
22-
>
21+
className="p-4 border border-zinc-800 rounded mt-4">
2322
<h2 className="font-bold">{post.title}</h2>
2423
<p className="mt-2">{post.content}</p>
2524
</div>
2625
))}
2726
</div>
2827
</main>
29-
)
30-
}
28+
);
29+
}

orm/clerk-nextjs/eslint.config.mjs

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)