NextJS, Flask backend (nextjs-auth0 library)

Hi, my goal is to build a dashboard (SPA) that helps visualize data processed using a Machine Learning algorithm.

I have built a Flask API that serves data from my database and checks/validates users using bearer tokens in the Authorization header. This API uses Auth0 to verify user info.

I have built a front-end using NextJS and am struggling with how I can use the nextjs-auth0 library to pass these bearer tokens to my API. I have followed the basic tutorial here and have all the login/logout pages.

The goal is to create a simple page on my NextJS front-end, which queries my Flask API at http://localhost:5000/data/datasets and returns a bunch of datasets. From my basic understanding, getServerSideProps should allow me to accomplish this. However, I am having trouble figuring out how I can pass the accessToken to this function. There’s the option of using the NextJS API routes as a proxy but I feel like this would be slow and defeats the purpose of a Flask backend…

Seems like a trivial problem but I’m quite new to NextJS and would appreciate any help here! Thank you.

1 Like

After looking at the README here, seems like I need to make use of the NextJS api concept i.e. I can’t directly fetch from my Flask API.

Would auth0-react be better/faster here because it makes direct calls to the Flask application?

### Comparison with the Auth0 React SDK
* You want to get the access token and call external API's directly from the frontend layer rather than using Next.js API Routes as a proxy to call external APIs