Skip to content

Commit 6175783

Browse files
committed
🔄 Synced local '.' with remote 'apps/examples/nextjs'
1 parent cbbde8e commit 6175783

File tree

14 files changed

+128
-102
lines changed

14 files changed

+128
-102
lines changed

app/api-example/page.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import { useEffect, useState } from "react"
55
export default function Page() {
66
const [data, setData] = useState()
77
useEffect(() => {
8-
;(async () => {
8+
; (async () => {
99
const res = await fetch("/api/protected")
1010
const json = await res.json()
1111
setData(json)
1212
})()
1313
}, [])
1414
return (
15-
<div className="space-y-2">
15+
<div className="flex flex-col gap-6">
1616
<h1 className="text-3xl font-bold">Route Handler Usage</h1>
1717
<p>
1818
This page fetches data from an API{" "}
@@ -25,10 +25,14 @@ export default function Page() {
2525
</CustomLink>{" "}
2626
method.
2727
</p>
28-
<h2 className="text-xl font-bold">Data from API Route:</h2>
29-
<pre>
30-
<code>{JSON.stringify(data, null, 2)}</code>
31-
</pre>
28+
<div className="flex flex-col rounded-md bg-neutral-100">
29+
<div className="p-4 font-bold rounded-t-md bg-neutral-200">
30+
Data from API Route
31+
</div>
32+
<pre className="py-6 px-4 whitespace-pre-wrap break-all">
33+
{JSON.stringify(data, null, 2)}
34+
</pre>
35+
</div>
3236
</div>
3337
)
3438
}

app/client-example/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { SessionProvider } from "next-auth/react"
55
export default async function ClientPage() {
66
const session = await auth()
77
if (session?.user) {
8-
// @ts-expect-error TODO: Look into https://react.dev/reference/react/experimental_taintObjectReference
8+
// TODO: Look into https://react.dev/reference/react/experimental_taintObjectReference
99
// filter out sensitive data before passing to client.
1010
session.user = {
1111
name: session.user.name,
@@ -15,7 +15,7 @@ export default async function ClientPage() {
1515
}
1616

1717
return (
18-
<SessionProvider session={session}>
18+
<SessionProvider basePath={"/auth"} session={session}>
1919
<ClientExample />
2020
</SessionProvider>
2121
)

app/globals.css

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,42 +34,13 @@
3434

3535
--radius: 0.5rem;
3636
}
37-
38-
.dark {
39-
--background: 222.2 84% 4.9%;
40-
--foreground: 210 40% 98%;
41-
42-
--card: 222.2 84% 4.9%;
43-
--card-foreground: 210 40% 98%;
44-
45-
--popover: 222.2 84% 4.9%;
46-
--popover-foreground: 210 40% 98%;
47-
48-
--primary: 210 40% 98%;
49-
--primary-foreground: 222.2 47.4% 11.2%;
50-
51-
--secondary: 217.2 32.6% 17.5%;
52-
--secondary-foreground: 210 40% 98%;
53-
54-
--muted: 217.2 32.6% 17.5%;
55-
--muted-foreground: 215 20.2% 65.1%;
56-
57-
--accent: 217.2 32.6% 17.5%;
58-
--accent-foreground: 210 40% 98%;
59-
60-
--destructive: 0 62.8% 30.6%;
61-
--destructive-foreground: 210 40% 98%;
62-
63-
--border: 217.2 32.6% 17.5%;
64-
--input: 217.2 32.6% 17.5%;
65-
--ring: 212.7 26.8% 83.9%;
66-
}
6737
}
6838

6939
@layer base {
7040
* {
7141
@apply border-border;
7242
}
43+
7344
body {
7445
@apply bg-background text-foreground;
7546
}

app/page.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import CustomLink from "@/components/custom-link"
2-
import packageJSON from "../package.json"
2+
import { auth } from "auth"
3+
4+
export default async function Index() {
5+
const session = await auth()
36

4-
export default function Index() {
57
return (
6-
<div className="space-y-2">
8+
<div className="flex flex-col gap-6">
79
<h1 className="text-3xl font-bold">NextAuth.js Example</h1>
8-
<p>
10+
<div>
911
This is an example site to demonstrate how to use{" "}
1012
<CustomLink href="https://nextjs.authjs.dev">NextAuth.js</CustomLink>{" "}
1113
for authentication. Check out the{" "}
@@ -17,12 +19,15 @@ export default function Index() {
1719
Client
1820
</CustomLink>{" "}
1921
examples to see how to secure pages and get session data.
20-
</p>
21-
<p>
22-
Current{" "}
23-
<CustomLink href="https://nextjs.authjs.dev">NextAuth.js</CustomLink>{" "}
24-
version: <em>next-auth@{packageJSON.dependencies["next-auth"]}</em>
25-
</p>
22+
</div>
23+
<div className="flex flex-col rounded-md bg-neutral-100">
24+
<div className="p-4 font-bold rounded-t-md bg-neutral-200">
25+
Current Session
26+
</div>
27+
<pre className="py-6 px-4 whitespace-pre-wrap break-all">
28+
{JSON.stringify(session, null, 2)}
29+
</pre>
30+
</div>
2631
</div>
2732
)
2833
}

auth.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ export const config = {
140140
if (pathname === "/middleware-example") return !!auth
141141
return true
142142
},
143+
jwt({ token, trigger, session }) {
144+
if (trigger === "update") token.name = session.user.name
145+
return token
146+
},
143147
},
144148
} satisfies NextAuthConfig
145149

components/client-example.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import CustomLink from "./custom-link"
99

1010
const UpdateForm = () => {
1111
const { data: session, update } = useSession()
12-
const [name, setName] = useState(session?.user?.name ?? "")
12+
const [name, setName] = useState(`New ${session?.user?.name}` ?? "")
1313

1414
if (!session?.user) return null
1515
return (
@@ -25,11 +25,11 @@ const UpdateForm = () => {
2525
console.log({ newSession })
2626
}
2727
}}
28-
className="flex items-center w-full max-w-sm space-x-2"
28+
className="flex items-center space-x-2 w-full max-w-sm"
2929
>
3030
<Input
3131
type="text"
32-
placeholder={session.user.name ?? ""}
32+
placeholder="New name"
3333
value={name}
3434
onChange={(e) => {
3535
setName(e.target.value)
@@ -43,9 +43,10 @@ const UpdateForm = () => {
4343

4444
export default function ClientExample() {
4545
const { data: session, status } = useSession()
46+
4647
return (
47-
<div className="space-y-2">
48-
<h1 className="text-3xl font-bold">Client Side Rendering Usage</h1>
48+
<div className="flex flex-col gap-4">
49+
<h1 className="text-3xl font-bold">Client Side Rendering</h1>
4950
<p>
5051
This page fetches session data client side using the{" "}
5152
<CustomLink href="https://nextjs.authjs.dev/react#usesession">

components/custom-link.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,14 @@ const CustomLink = ({
2828
href={href}
2929
target="_blank"
3030
rel="noopener noreferrer"
31-
className={cn("items-center underline", className)}
31+
className={cn(
32+
"inline-flex align-baseline gap-1 items-center underline underline-offset-4",
33+
className
34+
)}
3235
{...rest}
3336
>
34-
{children}
35-
<ExternalLink className=" ml-0.5 h-4 w-4 inline-block" />
37+
<span>{children}</span>
38+
<ExternalLink className="inline-block ml-0.5 w-4 h-4" />
3639
</Link>
3740
)
3841
}

components/footer.tsx

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
import CustomLink from "./custom-link"
2+
import packageJSON from "next-auth/package.json"
23

34
export default function Footer() {
45
return (
5-
<footer className="flex flex-col w-full px-4 mx-0 my-4 space-y-1 text-sm md:max-w-3xl md:my-12 md:mx-auto sm:px-6 md:h-5 md:items-center md:space-y-0 md:space-x-4 md:flex-row">
6-
<CustomLink href="https://nextjs.authjs.dev">Documentation</CustomLink>
7-
<CustomLink href="https://www.npmjs.com/package/next-auth">
8-
NPM
9-
</CustomLink>
10-
<CustomLink href="https://github.com/nextauthjs/next-auth/tree/main/apps/examples/nextjs">
11-
Source on GitHub
12-
</CustomLink>
13-
<CustomLink href="/policy">Policy</CustomLink>
6+
<footer className="flex flex-col gap-4 px-4 my-4 mx-0 w-full text-sm sm:flex-row sm:justify-between sm:items-center sm:px-6 sm:my-12 sm:mx-auto sm:max-w-3xl sm:h-5">
7+
<div className="flex flex-col gap-4 sm:flex-row">
8+
<CustomLink href="https://nextjs.authjs.dev">Documentation</CustomLink>
9+
<CustomLink href="https://www.npmjs.com/package/next-auth">
10+
NPM
11+
</CustomLink>
12+
<CustomLink href="https://github.com/nextauthjs/next-auth/tree/main/apps/examples/nextjs">
13+
Source on GitHub
14+
</CustomLink>
15+
<CustomLink href="/policy">Policy</CustomLink>
16+
</div>
17+
<div className="flex gap-2 justify-start items-center">
18+
<img
19+
className="size-5"
20+
src="https://authjs.dev/img/logo/logo-sm.webp"
21+
alt="Auth.js Logo"
22+
/>
23+
<CustomLink href="https://npmjs.org/package/next-auth">
24+
{packageJSON.version}
25+
</CustomLink>
26+
</div>
1427
</footer>
1528
)
1629
}

components/main-nav.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,24 @@ import { Button } from "./ui/button"
1818

1919
export function MainNav() {
2020
return (
21-
<div className="flex items-center space-x-2 lg:space-x-6">
21+
<div className="flex gap-4 items-center">
2222
<CustomLink href="/">
2323
<Button variant="ghost" className="p-0">
24-
<Image src="/logo.png" alt="Home" width="32" height="32" />
24+
<Image
25+
src="/logo.png"
26+
alt="Home"
27+
width="32"
28+
height="32"
29+
className="min-w-8"
30+
/>
2531
</Button>
2632
</CustomLink>
2733
<NavigationMenu>
2834
<NavigationMenuList>
2935
<NavigationMenuItem>
30-
<NavigationMenuTrigger>Server Side</NavigationMenuTrigger>
36+
<NavigationMenuTrigger className="px-2">
37+
Server Side
38+
</NavigationMenuTrigger>
3139
<NavigationMenuContent>
3240
<ul className="grid gap-3 p-6 md:w-[400px] lg:w-[500px] lg:grid-cols-[.75fr_1fr]">
3341
<ListItem href="/server-example" title="RSC Example">

components/session-data.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Session } from "next-auth"
33
export default function SessionData({ session }: { session: Session | null }) {
44
if (session?.user) {
55
return (
6-
<div className="w-full space-y-2 overflow-auto">
6+
<div className="flex flex-col gap-4 w-full">
77
<h2 className="text-xl font-bold">Current Session Data</h2>
88
{Object.keys(session.user).length > 3 ? (
99
<p>
@@ -18,7 +18,14 @@ export default function SessionData({ session }: { session: Session | null }) {
1818
the page to avoid exposing sensitive information.
1919
</p>
2020
)}
21-
<pre>{JSON.stringify(session, null, 2)}</pre>
21+
<div className="flex flex-col rounded-md bg-neutral-100">
22+
<div className="p-4 font-bold rounded-t-md bg-neutral-200">
23+
Session
24+
</div>
25+
<pre className="py-6 px-4 whitespace-pre-wrap break-all">
26+
{JSON.stringify(session, null, 2)}
27+
</pre>
28+
</div>
2229
</div>
2330
)
2431
}

0 commit comments

Comments
 (0)