Skip to content

Commit 04c8532

Browse files
authored
Update 01-login.md
1 parent 8923fcc commit 04c8532

File tree

1 file changed

+39
-40
lines changed

1 file changed

+39
-40
lines changed

articles/quickstart/webapp/nextjs/01-login.md

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -84,45 +84,7 @@ export const auth0 = new Auth0Client({
8484
});
8585
```
8686

87-
88-
### Add the dynamic API route handler
89-
90-
Create a file at `app/api/shows/route.js`. This is your route Handler file using <a href="https://nextjs.org/docs/app/building-your-application/routing/route-handlers#dynamic-route-segments" target="_blank" rel="noreferrer">Dynamic Route Segment</a>. The file declares a `GET` export to call the `shows()` method from the SDK to create the API routes. import the `handleAuth` method from the SDK and call it from the `GET` export.
91-
92-
```javascript
93-
// app/api/shows/route.js
94-
import { NextResponse } from 'next/server';
95-
import { auth0 } from '../../../lib/auth0';
96-
97-
export const GET = async function shows() {
98-
try {
99-
const session = await auth0.getSession();
100-
101-
if (!session) {
102-
return NextResponse.json(
103-
{ error: 'Not authenticated' },
104-
{ status: 401 }
105-
);
106-
}
107-
108-
const res = new NextResponse();
109-
const { token: accessToken } = await auth0.getAccessToken();
110-
const apiPort = process.env.API_PORT || 3001;
111-
const response = await fetch(`http://localhost:${apiPort}/api/shows`, {
112-
headers: {
113-
Authorization: `Bearer ${accessToken}`
114-
}
115-
});
116-
const shows = await response.json();
117-
118-
return NextResponse.json(shows, res);
119-
} catch (error) {
120-
return NextResponse.json({ error: error.message }, { status: error.status || 500 });
121-
}
122-
};
123-
```
124-
125-
Upon execution, the following routes are available:
87+
The SDK auto-configures the following routes:
12688

12789
- `/auth/login`: The route to perform login with Auth0
12890
- `/auth/logout`: The route to log the user out
@@ -243,7 +205,44 @@ export default async function ProfileServer() {
243205

244206
:::panel Checkpoint
245207
Verify that you can display the `user.name` or <a href="https://auth0.com/docs/users/user-profile-structure#user-profile-attributes" target="_blank" rel="noreferrer">any other</a> `user` property within a component correctly after you have logged in.
246-
:::
208+
:::
209+
210+
### Create custom routes using the dynamic API route handler
211+
212+
Create the file at `app/api/shows/route.js`. This is your route Handler file using <a href="https://nextjs.org/docs/app/building-your-application/routing/route-handlers#dynamic-route-segments" target="_blank" rel="noreferrer">Dynamic Route Segment</a>. The file declares a `GET` export to call the `shows()` method from the SDK to create custom API routes. import the `handleAuth` method from the SDK and call it from the `GET` export.
213+
214+
```javascript
215+
// app/api/shows/route.js
216+
import { NextResponse } from 'next/server';
217+
import { auth0 } from '../../../lib/auth0';
218+
219+
export const GET = async function shows() {
220+
try {
221+
const session = await auth0.getSession();
222+
223+
if (!session) {
224+
return NextResponse.json(
225+
{ error: 'Not authenticated' },
226+
{ status: 401 }
227+
);
228+
}
229+
230+
const res = new NextResponse();
231+
const { token: accessToken } = await auth0.getAccessToken();
232+
const apiPort = process.env.API_PORT || 3001;
233+
const response = await fetch(`http://localhost:${apiPort}/api/shows`, {
234+
headers: {
235+
Authorization: `Bearer ${accessToken}`
236+
}
237+
});
238+
const shows = await response.json();
239+
240+
return NextResponse.json(shows, res);
241+
} catch (error) {
242+
return NextResponse.json({ error: error.message }, { status: error.status || 500 });
243+
}
244+
};
245+
```
247246

248247
## What's next?
249248

0 commit comments

Comments
 (0)