Skip to content

Commit 30704c6

Browse files
committed
Fixing the URLs on V4 migration guide
1 parent 95ba058 commit 30704c6

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

EXAMPLES.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ Additionally to the ability to initialize the interactive login process by redir
913913
the `startInteractiveLogin` method can also be called programmatically.
914914

915915
```typescript
916-
import { auth0 } from "./lib/auth0";
916+
import { auth0 } from "./lib/auth0"; // Adjust path if your auth0 client is elsewhere
917917
import { NextRequest } from "next/server";
918918

919919
export const GET = async (req: NextRequest) => {
@@ -937,7 +937,7 @@ export const auth0 = new Auth0Client({
937937
The second option is by configuring `authorizationParams` when calling `startInteractiveLogin`:
938938

939939
```ts
940-
import { auth0 } from "./lib/auth0";
940+
import { auth0 } from "./lib/auth0"; // Adjust path if your auth0 client is elsewhere
941941
import { NextRequest } from "next/server";
942942

943943
export const GET = async (req: NextRequest) => {
@@ -958,7 +958,7 @@ export const GET = async (req: NextRequest) => {
958958
When calling `startInteractiveLogin`, the `returnTo` parameter can be configured to specify where you would like to redirect the user to after they have completed their authentication and have returned to your application.
959959

960960
```ts
961-
import { auth0 } from "./lib/auth0";
961+
import { auth0 } from "./lib/auth0"; // Adjust path if your auth0 client is elsewhere
962962
import { NextRequest } from "next/server";
963963

964964
export const GET = async (req: NextRequest) => {

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Create a `middleware.ts` file in the root of your project's directory:
7272
```ts
7373
import type { NextRequest } from "next/server"
7474

75-
import { auth0 } from "./lib/auth0"
75+
import { auth0 } from "./lib/auth0" // Adjust path if your auth0 client is elsewhere
7676
7777
export async function middleware(request: NextRequest) {
7878
return await auth0.middleware(request)

V4_MIGRATION_GUIDE.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ In v4, the routes are now mounted automatically by the middleware:
4141
```ts
4242
import type { NextRequest } from "next/server"
4343

44-
import { auth0 } from "./lib/auth0"
44+
import { auth0 } from "./lib/auth0" // Adjust path if your auth0 client is elsewhere
4545
4646
export async function middleware(request: NextRequest) {
4747
return await auth0.middleware(request)
@@ -68,7 +68,7 @@ When configuring your application to use v4 of the SDK, it is now **required** t
6868

6969
import type { NextRequest } from "next/server"
7070

71-
import { auth0 } from "./lib/auth0"
71+
import { auth0 } from "./lib/auth0" // Adjust path if your auth0 client is elsewhere
7272
7373
export async function middleware(request: NextRequest) {
7474
return await auth0.middleware(request) // Returns a NextResponse object
@@ -87,7 +87,7 @@ export const config = {
8787
}
8888
```
8989
> [!NOTE]
90-
> The above middleware is a basic setup. Its primary function is to pass incoming requests to the Auth0 SDK's request handler, which in turn manages the [default auto-mounted authentication routes](../README.md#routes), user sessions, and the overall authentication flow.
90+
> The above middleware is a basic setup. It passes incoming requests to the Auth0 SDK's request handler, which in turn manages the [default auto-mounted authentication routes](https://github.com/auth0/nextjs-auth0/blob/main/README.md#routes), user sessions, and the overall authentication flow. It does **not** protect any routes by default, in order to protect routes from unauthenticated users, read the section below on [protecting routes](https://github.com/auth0/nextjs-auth0/blob/main/V4_MIGRATION_GUIDE.md#protecting-routes).
9191
9292
See [the Getting Started section](https://github.com/auth0/nextjs-auth0/tree/main?tab=readme-ov-file#getting-started) for details on how to configure the middleware.
9393

@@ -99,7 +99,7 @@ By default, **the middleware does not protect any routes**. To protect a page, y
9999
export async function middleware(request) {
100100
const authRes = await auth0.middleware(request); // Returns a NextResponse object
101101

102-
// Ensure our own middleware does not handle the `/auth` routes, auto-mounted and handled by the SDK
102+
// Ensure your own middleware does not handle the `/auth` routes, auto-mounted and handled by the SDK
103103
if (request.nextUrl.pathname.startsWith("/auth")) {
104104
return authRes;
105105
}
@@ -109,6 +109,7 @@ export async function middleware(request) {
109109
return authRes;
110110
}
111111

112+
// Any route that gets to this point will be considered a protected route, and require the user to be logged-in to be able to access it
112113
const { origin } = new URL(request.url)
113114
const session = await auth0.getSession()
114115

@@ -126,25 +127,25 @@ export async function middleware(request) {
126127
> [!NOTE]
127128
> We recommend keeping the security checks as close as possible to the data source you're accessing. This is also in-line with [the recommendations from the Next.js team](https://nextjs.org/docs/app/building-your-application/authentication#optimistic-checks-with-middleware-optional).
128129
129-
For more examples on accessing user sessions in middleware, see [Accessing the authenticated user in Middleware in the Examples guide](./EXAMPLES.md#middleware).
130+
For more examples on accessing user sessions in middleware, see [Accessing the authenticated user in Middleware in the Examples guide](https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#middleware).
130131

131132
### Combining with other middleware
132133

133-
For scenarios where you need to combine the Auth0 middleware with other Next.js middleware, please refer to the [Combining middleware](../EXAMPLES.md#combining-middleware) guide for examples and best practices.
134+
For scenarios where you need to combine the Auth0 middleware with other Next.js middleware, please refer to the [Combining middleware](https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#combining-middleware) guide for examples and best practices.
134135

135-
## Changes to `<UserProvider />`
136+
## Migrating `<UserProvider />` to `<Auth0Provider />`
136137

137138
The `<UserProvider />` has been renamed to `<Auth0Provider />`.
138139

139140
Previously, when setting up your application to use v3 of the SDK, it was required to wrap your layout in the `<UserProvider />`. **This is no longer required by default.**
140141

141-
If you would like to pass an initial user during server rendering to be available to the `useUser()` hook, you can wrap your components with the new `<Auth0Provider />` ([see example](https://github.com/auth0/nextjs-auth0/tree/main?tab=readme-ov-file#auth0provider-)).
142+
If you would like to pass an initial user during server rendering to be available to the `useUser()` hook, you can wrap your components with the new `<Auth0Provider />` ([see example](https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#auth0provider-)).
142143

143144
## Rolling sessions
144145

145146
In v4, rolling sessions are enabled by default and are handled automatically by the middleware with no additional configuration required.
146147

147-
See the [session configuration section](https://github.com/auth0/nextjs-auth0/tree/main?tab=readme-ov-file#session-configuration) for additional details on how to configure it.
148+
See the [session configuration section](https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#session-configuration) for additional details on how to configure it.
148149

149150
## Migrating from `withPageAuthRequired` and `withApiAuthRequired`
150151

@@ -174,7 +175,7 @@ The `getSession()` method can be used in the App Router in Server Components, Se
174175

175176
In the Pages Router, the `getSession(req)` method takes a request object and can be used in `getServerSideProps`, API routes, and middleware.
176177

177-
Read more about [accessing the authenticated user in various contexts (browser, server, middleware) in the Examples guide](./EXAMPLES.md#accessing-the-authenticated-user).
178+
Read more about [accessing the authenticated user in various contexts (browser, server, middleware) in the Examples guide](https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#accessing-the-authenticated-user).
178179

179180
In the browser, you can rely on the `useUser()` hook to check if the user is authenticated. For example:
180181

@@ -231,7 +232,7 @@ export const auth0 = new Auth0Client({
231232
})
232233
```
233234

234-
Read more about [passing authorization parameters](https://github.com/auth0/nextjs-auth0/tree/main?tab=readme-ov-file#passing-authorization-parameters).
235+
Read more about [passing authorization parameters](https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#passing-authorization-parameters).
235236

236237
## ID token claims
237238

@@ -250,7 +251,7 @@ In v4, by default, the only claims that are persisted in the `user` object of se
250251
- `org_id`
251252

252253
If you'd like to customize the `user` object to include additional custom claims from the ID token, you can use the `beforeSessionSaved` hook (see [beforeSessionSaved hook](https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#beforesessionsaved))
253-
For a list of default claims included in the user object, refer to the [ID Token claims and the user object section in the Examples guide](./EXAMPLES.md#id-token-claims-and-the-user-object).
254+
For a list of default claims included in the user object, refer to the [ID Token claims and the user object section in the Examples guide](https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#id-token-claims-and-the-user-object).
254255

255256
## Handling Dynamic Base URLs (e.g. Vercel Preview Deployments)
256257
When deploying to platforms like Vercel with dynamic preview URLs, it's important to set the correct appBaseUrl and redirect_uri at runtime — especially in preview environments where URLs change per deployment.
@@ -281,7 +282,7 @@ export const auth0 = new Auth0Client({
281282
## Additional changes
282283

283284
- By default, v4 is edge-compatible and as such there is no longer a `@auth0/nextjs-auth0/edge` export.
284-
- All cookies set by the SDK default to `SameSite=Lax`. For details on how to customize cookie attributes, see the [Cookie Configuration section in the Examples guide](./EXAMPLES.md#cookie-configuration).
285-
- `touchSession` method was removed. The middleware enables rolling sessions by default and can be configured via the [Session configuration section in the Examples guide](./EXAMPLES.md#session-configuration).
286-
- `getAccessToken` can now be called in React Server Components. For examples on how to use `getAccessToken` in various environments (browser, App Router, Pages Router, Middleware), refer to the [Getting an access token section in the Examples guide](./EXAMPLES.md#getting-an-access-token).
285+
- All cookies set by the SDK default to `SameSite=Lax`. For details on how to customize cookie attributes, see the [Cookie Configuration section in the Examples guide](https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#cookie-configuration).
286+
- `touchSession` method was removed. The middleware enables rolling sessions by default and can be configured via the [Session configuration section in the Examples guide](https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#session-configuration).
287+
- `getAccessToken` can now be called in React Server Components. For examples on how to use `getAccessToken` in various environments (browser, App Router, Pages Router, Middleware), refer to the [Getting an access token section in the Examples guide](https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#getting-an-access-token).
287288
- By default, v4 will use [OpenID Connect's RP-Initiated Logout](https://auth0.com/docs/authenticate/login/logout/log-users-out-of-auth0) if it's enabled on the tenant. Otherwise, it will fallback to the `/v2/logout` endpoint.

0 commit comments

Comments
 (0)