Next.js Discord

Discord Forum

Shared Auth Logic

Unanswered
Giant panda posted this in #help-forum
Open in Discord
Giant pandaOP
At the moment after following the https://nextjs.org/docs/app/building-your-application/authentication tutorial im left with
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?

0 Replies