Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next15 support #125

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }) => {
Copy link

@edproton edproton Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The arrow function is lacking async here.

It should be

export default convexAuthNextjsMiddleware(async (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