Skip to content

Commit

Permalink
Improve the dynamic API route instructions (#10050)
Browse files Browse the repository at this point in the history
  • Loading branch information
Widcket authored Apr 19, 2022
1 parent 84d5c30 commit 3e6cb50
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions articles/quickstart/webapp/nextjs/01-login.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ The SDK will read these values from the Node.js process environment and automati

### Add the dynamic API route

Inside the `pages/api` directory, create the file `auth/[...auth0].js`. Import in that file the `handleAuth` method from the SDK, and export the result of calling it.
Create an `auth` directory under the `pages/api` directory. Then, create a `[...auth0].js` file under the newly created `auth` directory. The path to your dynamic API route file should then be `pages/api/auth/[...auth0].js`.

Import in that file the `handleAuth` method from the SDK, and export the result of calling it.

```javascript
// pages/api/auth/[...auth0].js
Expand All @@ -59,14 +61,13 @@ import { handleAuth } from '@auth0/nextjs-auth0';
export default handleAuth();
```

This creates the following routes:
Under the hood, `handleAuth()` creates the following routes:

- `/api/auth/login`: The route used to perform login with Auth0.
- `/api/auth/logout`: The route used to log the user out.
- `/api/auth/callback`: The route Auth0 will redirect the user to after a successful login.
- `/api/auth/me`: The route to fetch the user profile from.


### Add the `UserProvider` component

On the frontend side, the SDK uses React Context to manage the authentication state of your users. To make that state available to all your pages, you need to override the [App component](https://nextjs.org/docs/advanced-features/custom-app) and wrap its inner component with a `UserProvider`. Create the file `pages/_app.js` as follows:
Expand Down

0 comments on commit 3e6cb50

Please sign in to comment.