Repository: auth0/nextjs-auth0 (ts)

Issue:
Redirects using withMiddlewareAuthRequired
### Checklist

- [X] The issue can be reproduced in the [sample app](https://github.com/auth0-samples/auth0-nextjs-samples/tree/main/Sample-01) (or N/A).
- [X] I have looked into the [README](https://github.com/auth0/nextjs-auth0#readme) and have not found a suitable solution or answer.
- [X] I have looked into the [examples](https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md) and have not found a suitable solution or answer.
- [X] I have looked into the [API documentation](https://auth0.github.io/nextjs-auth0/) and have not found a suitable solution or answer.
- [X] I have searched the [issues](https://github.com/auth0/nextjs-auth0/issues) and have not found a suitable solution or answer.
- [X] I have searched the [Auth0 Community](https://community.auth0.com/c/sdks/5) forums and have not found a suitable solution or answer.
- [X] I agree to the terms within the [Auth0 Code of Conduct](https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md).

### Description

Making a redirect with `withMiddlewareAuthRequired`:

```tsx
export default withMiddlewareAuthRequired(async function middleware(
  req: NextRequest
) {
  return NextResponse.redirect("/register")
})
```

strips the status code and always returns a 200. That means that the document body results in `/register`.

This:
```tsx
export default async function middleware(
  req: NextRequest
) {
  return NextResponse.redirect("/register")
}
```

works fine...

### Reproduction

See description.

### SDK version

2.0.0

### Next.js version

12.3.1

### Node.js version

18.8

Pull request:
status getter is not enumerable so needs to be added to NextResponse
fixes #874 

Patch:
diff --git a/src/helpers/with-middleware-auth-required.ts b/src/helpers/with-middleware-auth-required.ts
index cf1efec3..faa03928 100644
--- a/src/helpers/with-middleware-auth-required.ts
+++ b/src/helpers/with-middleware-auth-required.ts
@@ -79,7 +79,7 @@ export default function withMiddlewareAuthRequiredFactory(
         if (cookies.length || authCookies.length) {
           headers.set('set-cookie', [...authCookies, ...cookies].join(', '));
         }
-        return NextResponse.next({ ...res, headers });
+        return NextResponse.next({ ...res, status: res.status, headers });
       } else {
         return authRes;
       }


Test patch:
diff --git a/tests/helpers/with-middleware-auth-required.test.ts b/tests/helpers/with-middleware-auth-required.test.ts
index a342bee3..507b2cac 100644
--- a/tests/helpers/with-middleware-auth-required.test.ts
+++ b/tests/helpers/with-middleware-auth-required.test.ts
@@ -126,6 +126,28 @@ describe('with-middleware-auth-required', () => {
     expect(middleware).toHaveBeenCalled();
   });
 
+  test('should honor redirects in custom middleware for authenticated users', async () => {
+    const middleware = jest.fn().mockImplementation(() => {
+      return NextResponse.redirect('https://example.com/redirect');
+    });
+    const res = await setup({ middleware, user: { name: 'dave' } });
+    expect(middleware).toHaveBeenCalled();
+    expect(res.status).toEqual(307);
+    expect(res.headers.get('location')).toEqual('https://example.com/redirect');
+    expect(res.headers.get('set-cookie')).toMatch(/^appSession=/);
+  });
+
+  test('should honor rewrites in custom middleware for authenticated users', async () => {
+    const middleware = jest.fn().mockImplementation(() => {
+      return NextResponse.rewrite('https://example.com/rewrite');
+    });
+    const res = await setup({ middleware, user: { name: 'dave' } });
+    expect(middleware).toHaveBeenCalled();
+    expect(res.status).toEqual(200);
+    expect(res.headers.get('x-middleware-rewrite')).toEqual('https://example.com/rewrite');
+    expect(res.headers.get('set-cookie')).toMatch(/^appSession=/);
+  });
+
   test('should set a session cookie if session is rolling', async () => {
     const res = await setup({ user: { name: 'dave' } });
     expect(res.status).toEqual(200);