How does the auth0-nextjs withMiddlewareAuthRequired function work?

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.

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.

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.

const credentials = await auth0.credentialsManager.getCredentials()

But this doesn’t work.

The cookie has the following values:

_xsrf=
username-localhost-8888=
appSession=

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

Hey again @Outbound5070 !

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

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