DOCS Search
Auth
Auth Server-Side Rendering Next.js guide
Setting up Server-Side Auth for Next.js
Next.js comes in two flavors: the App Router and the Pages Router. You can set up Server-Side
Auth with either strategy. You can even use both in the same application.
App Router Pages Router Hybrid router strategies
You can use both the App and Pages Routers together.
Follow the instructions for both the App and Pages Routers. Whenever you need to connect to
Supabase, import the createClient utility that you need:
Router Code location Which createClient to use
App Router Server Component, Server Action, or Route Handler server.ts
Client Component client.ts
Pages Router getServerSideProps server-props.ts
getStaticProps static-props.ts
Component component.ts
API route api.ts
Remember to create the middleware.ts file for the App Router so the session refreshes for App
Router pages.
Edit this page on GitHub
Need some help? Contact support
Latest product updates? See Changelog
Something's not right? Check system status
© Supabase Inc
Contributing
Author Styleguide
Open Source
SupaSquad
Privacy Settings