new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Next.js App Router · all subjects

authentication & security

6 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Use client-only package for client-only logic

The `client-only` package can be used to mark modules that contain client-only logic, such as code that accesses the `window` object. This is the counterpart to `server-only` for client-side code.

server-only and client-only installation is optional in Next.js

In Next.js, installing `server-only` or `client-only` packages is optional. However, if your linting rules flag extraneous dependencies, you may install them to avoid issues.

Prevent server-only code from being imported into Client Components

Use the `server-only` package to prevent accidental usage of server-only code in Client Components. Import 'server-only' at the top of files containing server-only code (like functions using API_KEY environment variables). If a Client Component tries to import a module marked with 'server-only', there will be a build-time error.

Only NEXT_PUBLIC_ environment variables are in client bundle

In Next.js, only environment variables prefixed with `NEXT_PUBLIC_` are included in the client bundle. Environment variables without this prefix are replaced with an empty string by Next.js.

Next.js handles server-only and client-only imports internally

Next.js provides its own handling of `server-only` and `client-only` imports to provide clearer error messages when a module is used in the wrong environment. The contents of these packages from NPM are not used by Next.js. Next.js also provides its own type declarations for TypeScript configurations where `noUncheckedSideEffectImports` is active.

Example: Preventing environment poisoning with server-only

Import 'server-only' at the top of lib/data.js containing an async getData function that uses process.env.API_KEY in headers. This prevents the function from being accidentally imported and executed in Client Components.

Give your agent this brain