Skip to content

Commit 14bb29b

Browse files
author
Paul Asjes
authored
Merge pull request #33 from workos/pma/update-authkit-nextjs
Bump authkit-nextjs and add example for edge functions
2 parents 84d84fa + 4ee5b17 commit 14bb29b

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"dependencies": {
1515
"@radix-ui/react-icons": "^1.3.0",
1616
"@radix-ui/themes": "^3.0.1",
17-
"@workos-inc/authkit-nextjs": "^0.10.0",
17+
"@workos-inc/authkit-nextjs": "^0.11.0",
1818
"next": "^14.2.5",
1919
"react": "^18",
2020
"react-dom": "^18"

src/api/get-name/route.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { getSession } from "@workos-inc/authkit-nextjs";
2+
import { NextResponse } from "next/server";
3+
4+
export const GET = async () => {
5+
// Use 'getSession' for edge functions that don't have access to headers
6+
const { user } = await getSession();
7+
8+
return NextResponse.json({ name: user.firstName });
9+
};

src/app/account/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { getUser } from "@workos-inc/authkit-nextjs";
1+
import { withAuth } from "@workos-inc/authkit-nextjs";
22
import { Text, Heading, TextField, Flex, Box } from "@radix-ui/themes";
33

44
export default async function AccountPage() {
5-
const { user, role, permissions } = await getUser({ ensureSignedIn: true });
5+
const { user, role, permissions } = await withAuth({ ensureSignedIn: true });
66

77
const userFields = [
88
["First name", user.firstName],

src/app/components/sign-in-button.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { getSignInUrl, getUser, signOut } from "@workos-inc/authkit-nextjs";
1+
import { getSignInUrl, withAuth, signOut } from "@workos-inc/authkit-nextjs";
22
import { Button, Flex } from "@radix-ui/themes";
33

44
export async function SignInButton({ large }: { large?: boolean }) {
5-
const { user } = await getUser();
5+
const { user } = await withAuth();
66
const authorizationUrl = await getSignInUrl();
77

88
if (user) {

src/app/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import NextLink from "next/link";
2-
import { getUser } from "@workos-inc/authkit-nextjs";
2+
import { withAuth } from "@workos-inc/authkit-nextjs";
33
import { Button, Flex, Heading, Text } from "@radix-ui/themes";
44
import { SignInButton } from "./components/sign-in-button";
55

66
export default async function HomePage() {
7-
const { user } = await getUser();
7+
const { user } = await withAuth();
88
return (
99
<Flex direction="column" align="center" gap="2">
1010
{user ? (

0 commit comments

Comments
 (0)