Next.js Discord

Discord Forum

How ot change Status of page and display 404 page inside a page ?

Unanswered
Ymh_ posted this in #help-forum
Open in Discord
I have a hook useAuth that handle the logic of authentication, and I want to change the status of the page to 404 is there is no user authenticated.

import { notFound } from "next/navigation";

const Cars = (props: Props) => {
  const {user} = useAuth()
  
  if(!user) {
    // here i want to set the statut of the page to 404
    notFound()
  }
  return <div>Cars</div>;
};

0 Replies