# How does the auth0-nextjs withMiddlewareAuthRequired function work?

**URL:** <https://community.auth0.com/t/how-does-the-auth0-nextjs-withmiddlewareauthrequired-function-work/128535>\
**Category:** Get Help\
**Tags:** authentication-sessions, sessions\
**Created:** [February 28, 2024, 8:53pm UTC](https://community.auth0.com/t/how-does-the-auth0-nextjs-withmiddlewareauthrequired-function-work/128535 "2024-02-28T20:53:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Outbound5070](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@Outbound5070](https://community.auth0.com/u/Outbound5070)\
**Post date:** [February 28, 2024, 8:53pm UTC](https://community.auth0.com/t/how-does-the-auth0-nextjs-withmiddlewareauthrequired-function-work/128535/1 "2024-02-28T20:53:34Z")

</div>

I have a NextJS app that has every route protected by the `withMiddlewareAuthRequired` function from the `@auth0/nextjs-auth0/edge` package.

The `middleware.js` file looks like this.

```auto
import { withMiddlewareAuthRequired } from '@auth0/nextjs-auth0/edge'

export default withMiddlewareAuthRequired()

```

The app is configured in the Auth0 dashboard. It’s deployed and everything works.

I want to make calls to the server actions of this app from a React Native app that uses the `react-native-auth0` package.

The React Native app is also configured in the Auth0 dashboard. It authenticates with the same users from the NextJS app.

I see the NextJS app is using a cookie to authenticate when I inspect the network calls.

I copied the cookie and pasted it into this call to `fetch` from the React Native app. This works. And I get the expected response.

```auto
const cookie = `cookie copied from NextJS authenticated API call`

const res = fetch(nextJsServerActionUri, {
  headers: {
    Cookie: cookie,
  },
})

```

I cannot figure out how to generate this cookie myself in the React Native app.

I’ve tried using the values I get from the auth0 `credentialsManager`.

```auto
const credentials = await auth0.credentialsManager.getCredentials()

```

But this doesn’t work.

The cookie has the following values:

```auto
_xsrf=
username-localhost-8888=
appSession=

```

How can I find out how this cookie is generated so I can create my own?

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [February 28, 2024, 11:22pm UTC](https://community.auth0.com/t/how-does-the-auth0-nextjs-withmiddlewareauthrequired-function-work/128535/3 "2024-02-28T23:22:34Z")

</div>

Hey again @Outbound5070 !

As far as I can tell what you are looking for isn’t supported:

> [@React native + nextjs + auth0](https://community.auth0.com/t/react-native-nextjs-auth0/100945/6):
>
> I got an answer: The Auth0 Next.js SDK is intended for web login and it uses cookie-based authentication and authorization instead of a token-based approach. Therefore, calling a protected Next.js API from another client is not supported.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [March 13, 2024, 11:23pm UTC](https://community.auth0.com/t/how-does-the-auth0-nextjs-withmiddlewareauthrequired-function-work/128535/4 "2024-03-13T23:23:25Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
