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

Fixed Authentication docs improper nesting of unordered list inside ordered list #62958

Merged
merged 4 commits into from
Mar 11, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,22 @@ Once a user is authenticated, you'll need to ensure the user is allowed to visit

Here's how to implement Middleware for authentication in Next.js:

1. **Setting Up Middleware:**
- Create a `middleware.ts` or `.js` file in your project's root directory.
- Include logic to authorize user access, such as checking for authentication tokens.
2. **Defining Protected Routes:**
- Not all routes require authorization. Use the `matcher` option in your Middleware to specify any routes that do not require authorization checks.
3. **Middleware Logic:**
- Write logic to verify if a user is authenticated. Check user roles or permissions for route authorization.
4. **Handling Unauthorized Access:**
- Redirect unauthorized users to a login or error page as appropriate.
#### Setting Up Middleware:

- Create a `middleware.ts` or `.js` file in your project's root directory.
- Include logic to authorize user access, such as checking for authentication tokens.

#### Defining Protected Routes:

- Not all routes require authorization. Use the `matcher` option in your Middleware to specify any routes that do not require authorization checks.

#### Middleware Logic:

- Write logic to verify if a user is authenticated. Check user roles or permissions for route authorization.

#### Handling Unauthorized Access:

- Redirect unauthorized users to a login or error page as appropriate.

Example Middleware file:

Expand Down