Skip to content

Commit ce45af5

Browse files
committed
Upgrade to Next 14, simplify code
1 parent dad112a commit ce45af5

File tree

14 files changed

+237
-256
lines changed

14 files changed

+237
-256
lines changed

.env.local.example

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
WORKOS_CLIENT_ID=
33
WORKOS_API_KEY=
44

5-
# The endpoint that WorkOS will redirect to after a user authenticates
6-
WORKOS_REDIRECT_URI="http://localhost:3000/api/callback"
7-
JWT_SECRET_KEY="your_secret_here"
5+
# Your JWT secret key
6+
JWT_SECRET_KEY=

next.config.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
/** @type {import('next').NextConfig} */
2-
const nextConfig = {
3-
experimental: {
4-
serverActions: true,
5-
},
6-
};
2+
const nextConfig = {};
73

84
module.exports = nextConfig;

package-lock.json

Lines changed: 59 additions & 64 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"eslint": "8.49.0",
1818
"eslint-config-next": "13.4.19",
1919
"jose": "^4.14.6",
20-
"next": "13.4.19",
20+
"next": "^14.0.1",
2121
"react": "18.2.0",
2222
"react-dom": "18.2.0",
2323
"react-query": "^3.39.3",

src/app/account/page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { getUser } from "../../auth";
12
import { Text, Heading, TextFieldInput, Flex, Box } from "@radix-ui/themes";
2-
import { getUser } from "../actions";
33

4-
export default async function ProtectedPage() {
4+
export default async function AccountPage() {
55
const { user } = await getUser();
66

77
const userFields = user && [
@@ -37,7 +37,7 @@ export default async function ProtectedPage() {
3737
</Text>
3838

3939
<Box grow="1">
40-
<TextFieldInput value={String(value)} readOnly />
40+
<TextFieldInput value={value || ""} readOnly />
4141
</Box>
4242
</label>
4343
</Flex>

src/app/actions.ts

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

src/app/api/callback/route.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { SignJWT } from "jose";
22
import { NextRequest, NextResponse } from "next/server";
3-
import { getJwtSecretKey, workos } from "@/libs/auth";
3+
import { getJwtSecretKey, workos, getClientId } from "../../../auth";
44

55
export async function GET(request: NextRequest) {
66
const code = request.nextUrl.searchParams.get("code");
@@ -9,27 +9,27 @@ export async function GET(request: NextRequest) {
99
try {
1010
// Use the code returned to us by AuthKit and authenticate the user with WorkOS
1111
const { user } = await workos.users.authenticateWithCode({
12-
clientId: process.env.WORKOS_CLIENT_ID || "",
12+
clientId: getClientId(),
1313
code,
1414
});
1515

1616
// Create a JWT token with the user's information
1717
const token = await new SignJWT({
18-
// Here you might lookup and retrieve user details from a database
18+
// Here you might lookup and retrieve user details from your database
1919
user,
2020
})
21-
.setProtectedHeader({ alg: "HS256" })
21+
.setProtectedHeader({ alg: "HS256", typ: "JWT" })
2222
.setIssuedAt()
2323
.setExpirationTime("1h")
2424
.sign(getJwtSecretKey());
2525

2626
const url = request.nextUrl.clone();
2727

28-
// Cleanup params from redirect
28+
// Cleanup params
2929
url.searchParams.delete("code");
30-
url.pathname = "/";
3130

32-
// Redirect to home page and store the session cookie
31+
// Redirect to the requested path and store the session
32+
url.pathname = "/";
3333
const response = NextResponse.redirect(url);
3434

3535
response.cookies.set({
@@ -41,9 +41,11 @@ export async function GET(request: NextRequest) {
4141

4242
return response;
4343
} catch (error) {
44-
return NextResponse.json({ success: false });
44+
return NextResponse.json(error);
4545
}
4646
}
4747

48-
return NextResponse.json({ success: false });
48+
return NextResponse.json({
49+
error: "No authorization code was received from AuthKit",
50+
});
4951
}

0 commit comments

Comments
 (0)