Hey, i'm trying to get a user session in a NextJS ...
# talk-kratos
a
Hey, i'm trying to get a user session in a NextJS middleware but I receive the error
adapter is not a function
. Which seems to be related to the fact that the middleware is executed in a edge runtime, but
@ory/client
uses
axios
which cannot be run in an edge runtime. Here is my current code:
Copy code
const ory = new FrontendApi(new Configuration(edgeConfig));

    const res = await ory.toSession(
      {
        cookie: cookie,
      },
      {
        baseURL: process.env.BASE_URL,
      }
    );
How would I go about replacing this code with something like
fetch
? Hope i'm making sense. Thanks!
l
You could try using https://github.com/vespaiach/axios-fetch-adapter Though it doesn’t work with the latest axios version
m
here is a brief tutorial using the adapter mentioned above https://www.ory.sh/use-ory-with-cloudflare-workers/
a
@limited-photographer-61008 Thanks for a quick response! Using vespaiach's fetch adapter yields a typescript error. Possibly because of the axios version. However @magnificent-energy-493’s link got me on the right track. Using
@haverstack/axios-fetch-adapter
seems to be working correctly. Thanks guys!
I'm curious, is there any specific reason why Ory is using
axios
instead of just
fetch
? I'm guessing because axios offers the adapter functionality... @magnificent-energy-493
m
You can use
fetch
with the API directly right? I used it in some projects. depending on what you want to do I think its feasible. But I am not sure why it was axios, its a very historic decision - I am sure there is some history on github, but I could not find anything concrete in a quick search.
l
Well, fetch wasn’t available in Node until recently
m
That sounds like a good reason 😄