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

withMiddlewareAuthRequired breaks Readablestream response #1150

Closed
7 tasks done
codewitch opened this issue Apr 8, 2023 · 2 comments
Closed
7 tasks done

withMiddlewareAuthRequired breaks Readablestream response #1150

codewitch opened this issue Apr 8, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@codewitch
Copy link

Checklist

  • The issue can be reproduced in the sample app (or N/A).
  • I have looked into the README and have not found a suitable solution or answer.
  • I have looked into the examples and have not found a suitable solution or answer.
  • I have looked into the API documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

Description

I have an nextjs edge api that returns a ReadableStream. It works great, but when i wrap it in a withMiddlewareAuthRequired to gate the api for users only the stream does not end up being returned.

Reproduction

the api code looks something like this. I have abstracted out the stream logic in to a getStream() function for simplicity:

export const config = {  runtime: "edge" };

export default withMiddlewareAuthRequired(async function middleware(req) {
  const completionsStream = await getStream();
  return new Response(completionsStream);
});

SDK version

2.4.0

Next.js version

13.3.0

Node.js version

18

@adamjmcgrath adamjmcgrath added the needs investigation This needs to be investigated further before proceeding label Apr 11, 2023
@adamjmcgrath
Copy link
Contributor

adamjmcgrath commented Apr 11, 2023

Hi @codewitch - thanks for raising this

Support for producing a response in Next.js middleware was added after we added withMiddlewareAuthRequired - so it does not currently support this use case. Let me schedule some work to fix this.

In the meantime, you should be able to use getSession as a workaround.

import { NextResponse } from "next/server";
import { getSession } from "@auth0/nextjs-auth0/edge";

export async function middleware(req) {
  const res = NextResponse.next();
  const session = await getSession(req, res);
  if (session) {
    // logged in
  } else {
    // redirect to login
  }
}

@Widcket Widcket added enhancement New feature or request and removed needs investigation This needs to be investigated further before proceeding labels Apr 17, 2023
@adamjmcgrath
Copy link
Contributor

👋 Support for responses from custom middleware has been added to https://github.com/auth0/nextjs-auth0/releases/tag/v3.0.0-beta.3

More info on the Beta can be found here #1235

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants