title: Next.js/Next-Auth/Apollo/GraphQL Setup
body: <p>I'm looking for recommendations on how to approach a next.js front end that uses Apollo and GraphQL to access a PostgreSQL database. I figured it made sense to separate the front and back end, but I'm realizing there are tradeoffs. Next.js and NextAuth.js seem designed to work well when using the Next.js API functionality.</p>
  <p>A few requirements:</p>
  <ol>
  <li>Data needs to be restricted based on the user (public, internal, admin).</li>
  <li>Using Google OAuth for signing in</li>
  </ol>
  <p>With this in mind, NextAuth.js gets more complicated if you want the back end to be aware of the user's access rights.</p>
  <p>However, if my apollo/graphql back end is independent there are definite benefits like:</p>
  <ol>
  <li>I can swap out the front end if ever needed so there's some flexibility</li>
  <li>Code and dependencies may be simpler than a combined front/back end</li>
  </ol>
  <p>My current challenge is that I've got NextAuth.js working within the Next.js app, but I haven't figured out how to control data access. The best idea I've got so far is some sort of token management that mixes NextAuth.js and my back end. That doesn't seem to be the way NextAuth.js is designed though so I'm rethinking the whole architecture and looking for suggestions.</p>
  <p>Thanks!</p>
  <p>I found a very brief discussion of a similar question here, but I'd love to hear how others would approach this.
  <a href="https://stackoverflow.com/questions/61979393/how-to-forward-user-sessions-in-next-js-graphql-decoupled-architecture">How to forward user sessions in Next.js + Graphql decoupled architecture?</a></p>