Hello, I've been struggling to make the setup for ...
# support-questions-legacy
y
Hello, I've been struggling to make the setup for Next.js with Edge Functions work. When following the new Next.js setup instructions, using a session guard for an API route works until that route is an edge funtion. To reproduce I updated the example you have linked and added
export const runtime = 'edge';
to the user route https://github.com/supertokens/next.js/blob/canary/examples/with-supertokens/app/api/user/route.ts This now causes the error
Module not found: Can't resolve 'zlib'
(same for
querystring
and
crypto
). e.g. when running in dev or even during build. Which i think is strange since the middleware uses withSession without issues an is supposed to be the same edge runtime. The only "workaround" I found was to tell webpack to stop polyfilling (with config below). But that breaks things elsewhere. Have you (or someone else in here) had similar experiences or a better solution? Any recommendations going forward for Next.js Edge Functions?
Copy code
const nextConfig = {
  webpack(config) {
    config.resolve.fallback = {
      ...config.resolve.fallback,
      crypto: false,
      querystring: false,
      zlib: false,
    };

    return config;
  },
}
r
hey @yves404
thanks for pointing this out.
@porcellus can help here when he is available.
p
hi. I'll check this out a bit later today.
> Which i think is strange Yup, same here. I'll investigate this in more detail. As far as I've seen middlewares should always run using the edge runtime
for the current matter, right now it looks like you can't use the SDK with the
runtime: "edge"
(I'll try and fix this later this week). As an alternative you could use this method of session verification: https://supertokens.com/docs/thirdpartyemailpassword/common-customizations/sessions/with-jwt/jwt-verification#method-1-using-jwks-endpoint-recommended
y
Would be amazing to have this working on Edge Functions. I prefer to not do manually verify the JWT to be honest 😉 We'll just hold off to switching to Edge Function for now. @porcellus please let me know if you find out more on this or if I can help in any way with the further investigation.
p
hi. Sadly I'll not be able to fix this today/this week.
it seems to be a bit bigger issue that requires a bit more research/work than I had time for this week. I've added an issue you can track: https://github.com/supertokens/supertokens-node/issues/745. I'll try and fit this into next week.
18 Views