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

Support edge runtime in app based routes #1257

Closed
5 tasks done
gerlv opened this issue Jun 17, 2023 · 7 comments
Closed
5 tasks done

Support edge runtime in app based routes #1257

gerlv opened this issue Jun 17, 2023 · 7 comments
Labels
enhancement New feature or request

Comments

@gerlv
Copy link

gerlv commented Jun 17, 2023

Checklist

  • I have looked into the Readme, Examples, and FAQ 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.

Describe the problem you'd like to have solved

NextJS Auth0 can work with edge runtime.

At the moment, only the middleware supports the edge runtime. You can't use edge based getSession in app routes.

Describe the ideal solution

Edge runtime supported for app based routes

Alternatives and current workarounds

Use nodejs runtime

Additional context

No response

@adamjmcgrath
Copy link
Contributor

Hi @gerlv

You can't use edge based getSession in app routes

You can use the edge based getSession in app based routes in the new Beta (see #1235)

eg.

import { getSession } from '@auth0/nextjs-auth0/edge';
import { NextRequest, NextResponse } from 'next/server';

const GET = async (req: NextRequest) => {
  const res = new NextResponse();
  const session = await getSession(req, res);

  return NextResponse.json(session?.user, res);
};

export { GET };

@adamjmcgrath adamjmcgrath added the question Further information is requested label Jun 20, 2023
@gerlv
Copy link
Author

gerlv commented Jun 20, 2023

@adamjmcgrath thank you for a code snippet, I can see it works, but as far as I can see this wouldn't work with app based routes, and you can't override handleAuth functionality as all imports are from @auth0/nextjs-auth0.

I.e. there is a way to get the session, but the large part of the functionality can't be used with edge runtime.

@adamjmcgrath
Copy link
Contributor

as I can see this wouldn't work with app based routes

Can you elaborate? The code snippet I shared works with app based routes (on the edge runtime) in the new beta, have tested it on the example app

but the large part of the functionality can't be used with edge runtime

We are currently working on supporting the rest of the functionality on the Edge runtime, should be landing in the new v3 Beta very soon

@adamjmcgrath adamjmcgrath added enhancement New feature or request and removed question Further information is requested labels Jun 21, 2023
@ekojsalim
Copy link

We are currently working on supporting the rest of the functionality on the Edge runtime, should be landing in the new v3 Beta very soon

Just to clarify, does this mean support for handleAuth for Cloudflare Workers i.e. transitioning from the node-only openid-client to something like oauth4webapi? Asking this since we are prospecting for authn solutions and this is a huge blocker for us.

@adamjmcgrath
Copy link
Contributor

Just to clarify, does this mean support for handleAuth for Cloudflare Workers i.e. transitioning from the node-only openid-client to something like oauth4webapi?

@ekojsalim - yes, that's correct.

We have a branch which adds support for all the functionality from the Node runtime to the Edge runtime (in the app directory) here https://github.com/auth0/nextjs-auth0/tree/edge-auth-handlers

It's code complete and ready to be shipped to the new Beta, we just have an issue with Next.js - which we have an open PR for here vercel/next.js#51665

@ekojsalim
Copy link

That's awesome. Was actually assessing whether to fork & patch but having this supported is great. Looking forward to v3 :)

@adamjmcgrath
Copy link
Contributor

👋 Full support for the edge runtime, including handleAuth 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