If you're new to Firebase or Next.js, you can follow this comprehensive, step-by-step guide on integrating Firebase Authentication with Next.js using next-firebase-auth-edge library:
To allow gradual adoption of latest Next.js features, next-firebase-auth-edge works interchangeably with getServerSideProps and legacy Api Routes
Supports latest Next.js features
Zero-bundle size
Minimal configuration: In contrary to other libraries, you don't have to define your own API routes or update your next.config.js file. All heavy lifting is done by the middleware.
Secure: Uses jose for JWT validation. Signs user cookies with rotating keys to mitigate the risk of cryptanalysis attacks