This is a Next.js project created using the whop-next-template
First, set the required environment variables:
NEXT_PUBLIC_WHOP_CLIENT_ID="WHOP CLIENT ID"
WHOP_CLIENT_SECRET="WHOP CLIENT SECRET"
WHOP_BOT_TOKEN="WHOP API KEY"
NEXTAUTH_URL="http://localhost:3000"
NEXTAUTH_SECRET="NEXTAUTH SECRET"
NEXT_PUBLIC_RECOMMENDED_PLAN_ID="PLAN ID"
NEXT_PUBLIC_REQUIRED_PASS="PASS ID"
Then, run the development server:
npm run dev
yarn dev
pnpm run dev
Open http://localhost:3000 with your browser to see the result.
This template offers examples on how to utilize next.js patterns in conjuction with @whop-sdk/core
to easily gate certain parts of your website.
The examples in this list show how to use getServerSideProps
in the pages
directoy
pages/ssr/index.tsx
- Adds the whopUser
to the page props. It renders a login button for logged-out users and a logout button for logged-in userspages/ssr/logged-in.tsx
- Only displays a page to logged-in users. If a logged-out user tries to access this page they will be redirected to/ssr
where they can log inpages/ssr/pass-gated.tsx
- Check if a user owns a specificPass
and only shows the page content if they do. If the user does not own the pass a button directing the user to the whop.com checkout page where they can buy a plan that unlocks the page.
pages/ssg/pass-gated.tsx
- This example shows how to usemiddleware
to prevent users without access to a certainPass
to visit this page. If a user that does not have access tries to request this page themiddleware
will redirect them to the whop.com checkout page where they can buy a plan that unlocks the page.
The examples in this list show how to use @whop-sdk/core
in the new app
directory added in [email protected]
app/app/ssr/page.tsx
: Thispage
shows how to obtain a user-scoped instaince of the WhopSDK UserService. If its able to obtain the sdk (the user is logged-in) it shows a logout button, if not it shows a login buttonapp/app/ssr/pass-gated/layout.tsx
: Thislayout
shows how to lock a layout (and its children) for users that don't own a specific pass. If no pass is owned it renders a button that allows the user to purchase a pass unlocking the layout on whop.comapp/app/ssr/pass-gated/page.tsx
: Thispage
is pass-gated without any extra setup as its parentlayout
(app/app/ssr/pass-gated/layout.tsx
) is already pass-gatedapp/app/ssg/pass-gated/page.tsx
: Thispage
is protected bymiddleware
, conceptually similar topages/ssg/pass-gated.tsx
pages/api/pass-gated.ts
: Thisapi route
uses the user session to obtain a user-scoped instance of the WhopSDKUserService
and then uses that to check if the authorised used owns a certain pass.
To learn more about Next.js, take a look at the following resources:
- WhopSDK Documentation - learn about Whop API features and how to use the SDK.
- Next.js Documentation - learn about Next.js features and API.
- Learn Next.js - an interactive Next.js tutorial.
You can check out this templates GitHub repository - your feedback and contributions are welcome!