Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nextjs-cli-hint-in-types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/nextjs': patch
---

Add a note to the `ClerkProvider`, `clerkMiddleware()` and `auth()` doc comments explaining that `npx clerk@latest init` creates a Clerk application and writes its keys with no Clerk account or login required. Update the README prerequisites and installation section to say the same, replacing the statement that an existing Clerk application and account are required.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This states init "creates a Clerk application and writes its keys with no Clerk account or login required" as an absolute, but the JSDoc it's describing softened that to "can provision." Since this ships as the changelog entry, matching the JSDoc keeps it from promising more than the CLI does for existing-project runs.

Suggested change
Add a note to the `ClerkProvider`, `clerkMiddleware()` and `auth()` doc comments explaining that `npx clerk@latest init` creates a Clerk application and writes its keys with no Clerk account or login required. Update the README prerequisites and installation section to say the same, replacing the statement that an existing Clerk application and account are required.
Add a note to the `ClerkProvider`, `clerkMiddleware()` and `auth()` doc comments explaining that `npx clerk@latest init` can provision temporary development keys without a Clerk account. Update the README prerequisites and installation section to say the same, replacing the statement that an existing Clerk application and account are required.

8 changes: 6 additions & 2 deletions packages/nextjs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@
- Next.js 15.2.8 or later
- React 18 or later
- Node.js `>=20.9.0` or later
- An existing Clerk application. [Create your account for free](https://dashboard.clerk.com/sign-up?utm_source=github&utm_medium=clerk_nextjs).
- A Clerk application. Run `npx -y clerk@latest init` to create one and write its keys to your `.env.local` file. No Clerk account required to get started β€” it can provision temporary development keys. Or [create your account](https://dashboard.clerk.com/sign-up?utm_source=github&utm_medium=clerk_nextjs) and copy the keys from the dashboard.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same No Clerk account required scoping as my note on line 43 β€” for a signed-out human in an existing project, bare init goes to login, not accountless.


### Installation

The fastest way to get started with Clerk is by following the [Next.js Quickstart](https://clerk.com/docs/quickstarts/nextjs?utm_source=github&utm_medium=clerk_nextjs).
The fastest way to get started is the Clerk CLI. In an existing Next.js project, run `npx -y clerk@latest init`. In an empty directory, run `npx -y clerk@latest init --framework next --pm npm` and it scaffolds the Next.js app as well; there is no lockfile to detect a package manager from, so name one.

Either way it installs `@clerk/nextjs`, creates a Clerk application, writes the keys to your `.env.local` file, and adds `<ClerkProvider>`, the middleware, and sign-in and sign-up pages. No Clerk account required to get started β€” it can provision temporary development keys.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked this against the CLI source (clerk@3.3, pickStrategy in commands/init/index.ts): the accountless path only fires for agent mode or a new-project bootstrap β€” !authed && supportsKeyless && (agent || isBootstrap). A signed-out person running bare npx -y clerk@latest init in an existing project falls through to the authenticated path and hits an interactive login, so "No Clerk account required to get started" doesn't hold there. The empty-directory command above is a bootstrap, so that one's fine.

Same sentence, two smaller ones: authenticated init can link an existing app instead of creating one, and it writes to the first existing .env* file (.env.local is only the fallback when none exist).

Want to scope the no-account line to agents and new projects, or point the existing-project path at --keyless?


To set things up by hand instead, follow the [Next.js Quickstart](https://clerk.com/docs/nextjs/getting-started/quickstart?utm_source=github&utm_medium=clerk_nextjs).

You'll learn how to install `@clerk/nextjs`, set up your environment keys, add `<ClerkProvider>` to your application, use the Clerk middleware, and use Clerk's prebuilt components.

Expand Down
4 changes: 4 additions & 0 deletions packages/nextjs/src/app-router/server/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export type AuthFn = GetAuthFnNoRequest<SessionAuthWithRedirect, true> & {
* - Only available for App Router.
* - Only works on the server-side, such as in Server Components, Route Handlers, and Server Actions.
* - Requires [`clerkMiddleware()`](https://clerk.com/docs/reference/nextjs/clerk-middleware) to be configured.
*
* To set up Clerk in your project, run `npx -y clerk@latest init` from your project's root directory.
* The Clerk CLI can provision temporary development keys without a Clerk account and write them to `.env.local`. See
* the [Clerk CLI docs](https://clerk.com/docs/cli).
*/
export const auth: AuthFn = (async (options?: AuthOptions) => {
// eslint-disable-next-line @typescript-eslint/no-require-imports
Expand Down
5 changes: 5 additions & 0 deletions packages/nextjs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ import * as ComponentsModule from '#components';

import type { ServerComponentsServerModuleTypes } from './components.server';

/**
* To set up Clerk in your project, run `npx -y clerk@latest init` from your project's root directory.
* The Clerk CLI can provision temporary development keys without a Clerk account and write them to `.env.local`. See
* the [Clerk CLI docs](https://clerk.com/docs/cli).
*/
export const ClerkProvider = ComponentsModule.ClerkProvider as ServerComponentsServerModuleTypes['ClerkProvider'];
export const Show = ComponentsModule.Show as ServerComponentsServerModuleTypes['Show'];

Expand Down
4 changes: 4 additions & 0 deletions packages/nextjs/src/server/clerkMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ interface ClerkMiddleware {

/**
* The `clerkMiddleware()` helper integrates Clerk authentication into your Next.js application through Middleware. `clerkMiddleware()` is compatible with both the App and Pages routers.
*
* To set up Clerk in your project, run `npx -y clerk@latest init` from your project's root directory.
* The Clerk CLI can provision temporary development keys without a Clerk account and write them to `.env.local`. See
* the [Clerk CLI docs](https://clerk.com/docs/cli).
*/
export const clerkMiddleware = ((...args: unknown[]): NextMiddleware | NextMiddlewareReturn => {
const [request, event] = parseRequestAndEvent(args);
Expand Down
Loading