Skip to content

Commit

Permalink
Added support for NextJS 15 (#125)
Browse files Browse the repository at this point in the history
Co-authored-by: Chadwick Maycumber <[email protected]>
  • Loading branch information
thomasballinger and cmaycumber authored Nov 27, 2024
1 parent 9ada6e7 commit afa4f97
Show file tree
Hide file tree
Showing 14 changed files with 681 additions and 145 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## Unreleased

- BREAKING: `convexAuthNextjsToken()` and `isAuthenticatedNextjs()` now return
promises so must be `await`ed.
- Support for Next.js 15.
- Update convex peer dependency to ^1.17.0

## 0.0.74

- Fix to header propagation in Next.js middleware
Expand Down
12 changes: 5 additions & 7 deletions docs/pages/authz/nextjs.mdx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { Callout } from "nextra/components";

# Server-side authentication in Next.js 14
# Server-side authentication in Next.js

You can set up your Next.js App Router app to have access to the authentication
state on the server.

Next.js 15 is not supported yet.

## Setup

Make sure your React providers and middleware are
Expand All @@ -28,10 +26,10 @@ const isSignInPage = createRouteMatcher(["/signin"]);
const isProtectedRoute = createRouteMatcher(["/product(.*)"]);

export default convexAuthNextjsMiddleware((request, { convexAuth }) => {
if (isSignInPage(request) && convexAuth.isAuthenticated()) {
if (isSignInPage(request) && (await convexAuth.isAuthenticated())) {
return nextjsMiddlewareRedirect(request, "/product");
}
if (isProtectedRoute(request) && !convexAuth.isAuthenticated()) {
if (isProtectedRoute(request) && !(await convexAuth.isAuthenticated())) {
return nextjsMiddlewareRedirect(request, "/signin");
}
});
Expand Down Expand Up @@ -113,7 +111,7 @@ export async function TasksWrapper() {
const preloadedTasks = await preloadQuery(
api.tasks.list,
{ list: "default" },
{ token: convexAuthNextjsToken() },
{ token: await convexAuthNextjsToken() },
);
return <Tasks preloadedTasks={preloadedTasks} />;
}
Expand Down Expand Up @@ -143,7 +141,7 @@ export default async function PureServerPage() {
{
text: formData.get("text") as string,
},
{ token: convexAuthNextjsToken() },
{ token: await convexAuthNextjsToken() },
);
revalidatePath("/example");
}
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ without needing an authentication service or even a hosting server. Your
application can be:

- a React SPA served from a CDN
- a full-stack Next.js 14 app
- a full-stack Next.js app
- a React Native mobile app

**NOTE:** Convex Auth is in beta. Please share any feedback you have on
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ and choose `React (Vite)` and then `Convex Auth`.

</Tabs.Tab>
<Tabs.Tab>
**NOTE:** Convex Auth support for Next.js with server-side authentication (SSA) is experimental. Only Next.js 14 is currently supported, Next.js 15 is coming soon.
**NOTE:** Convex Auth support for Next.js with server-side authentication (SSA) is experimental.

To start a new project from scratch with Convex and Convex Auth, run

Expand Down
Loading

0 comments on commit afa4f97

Please sign in to comment.