Set up a waitlist in your Next.js app
In Waitlist mode, users can register their interest in your app by joining a waitlist. This mode is ideal for apps in early development stages or those wanting to generate interest before launch. This guide shows you how to get Clerk integrated and how to add a waitlist to your Next.js application.
Install @clerk/nextjs
Clerk's Next.js SDK gives you access to prebuilt components, React hooks, and helpers to make user authentication easier.
Run the following command to install the SDK:
Enable Waitlist mode
To enable Waitlist mode, follow these steps:
- In the Clerk Dashboard, navigate to the Restrictions page.
- Under the Sign-up modes section, enable Waitlist.
To manage users on your waitlist:
- In the Clerk Dashboard, navigate to the Waitlist page.
- On the right-side of a user's row, select the menu icon (...).
- Select Invite to invite the user to your application. Select Deny to deny the user access to your application.
Add the <Waitlist />
component
The <Waitlist />
component renders a form that allows users to join for early access to your app.
The following example includes a basic implementation of the <Waitlist />
component hosted on the /
route (the home page). You can use this as a starting point for your own implementation.
Add <ClerkProvider>
to your app
The <ClerkProvider>
component wraps your app to provide active session and user context to Clerk's hooks and other components. To use the <Waitlist />
component in your app, you must provide the waitlistUrl
prop, which points to the URL of your waitlist page.
Add sign-in functionality
To allow users to sign in once they've been approved from the waitlist, you must:
Add clerkMiddleware()
to your app
clerkMiddleware()
grants you access to user authentication state throughout your app, on any route or page. It also allows you to protect specific routes from unauthenticated users. To add clerkMiddleware()
to your app, follow these steps:
- Create a
middleware.ts
file.
- If you're using the
/src
directory, createmiddleware.ts
in the/src
directory. - If you're not using the
/src
directory, createmiddleware.ts
in the root directory alongside.env.local
.
- In your
middleware.ts
file, export theclerkMiddleware()
helper:
- By default,
clerkMiddleware()
will not protect any routes. All routes are public and you must opt-in to protection for routes. See theclerkMiddleware()
reference to learn how to require authentication for specific routes.
Add a sign-in page
The following example demonstrates how to render the <SignIn />
component.
Update your environment variables to point to your custom sign-in page. For more information on building custom sign-in and sign-up pages, see the dedicated guide.
Feedback
Last updated on