For the complete documentation index, see llms.txt. This page is also available as Markdown.

Private Pages

Pages like Dashboard need authentication checks, learn how to protect them.

Pages

To protect your app pages, simply take advantage of the NextAuth Session Hook:

import { useSession } from "next-auth/react";

export default function ExamplePage() {
  const session = useSession();
  
  if (session.status === "unauthenticated") router.push("/");
  
return (
    <section>
      {session.status === "loading" && <div>Please wait</div>}
      {session.status === "unauthenticated" && <div>Please log in</div>}
      {session.status === "authenticated" && <div>Hello World</div>}
    </section>
  )
}

API

You should always protect your backend calls to avoid malicious behavior, it's similar to pages thanks to NextAuth:

Last updated