Shared Auth Logic
Unanswered
Giant panda posted this in #help-forum
Giant pandaOP
At the moment after following the https://nextjs.org/docs/app/building-your-application/authentication tutorial im left with
Am I required to have this auth code on every page now? or could a middleware somehow take care of it?
export default async function Dashboard() {
// User authentication and role verification
const session = await verifySession();
if (!session) {
// User is not authenticated
return new Response(null, { status: 401 });
}
const user = await getUser();
return (
<div>
<h1>Dashboard</h1>
<p>Welcome to the dashboard, {user.username}!</p>
</div>
)
}Am I required to have this auth code on every page now? or could a middleware somehow take care of it?