Question · Next.js course · Module 7: Authentication and Authorization

Context Provider for Authentication

Why do you create a separate AuthProvider as a Client Component wrapping the application in Next.js?

Answer options

  • Because Next.js requires every provider to be in a separate file
  • Because Server Components cannot import any external libraries
  • Because React context (useContext) requires a Client Component, and layout.tsx is a Server Component by default
  • Because authentication data can only be stored in localStorage

You can check the correct answer by solving this task in the CodeWorlds game.