This is a template for integrating Privy Auth into a NextJS project. Check out the deployed app here!
This demo uses NextJS's App Router. If you'd like to see an example using the Pages Router, just change the branch of this repository to main.
- Clone this repository and open it in your terminal.
git clone https://github.com/privy-io/create-next-app- To use the version of this demo with the App Router, checkout the
app-routerbranch locally:
git checkout app-router- Install the necessary dependencies (including Privy Auth) with
npm.
npm i - Initialize your environment variables by copying the
.env.examplefile to an.env.localfile. Then, in.env.local, paste your Privy App ID from the console.
# In your terminal, create .env.local from .env.example
cp .env.example .env.local
# Add your Privy App ID to .env.local
NEXT_PUBLIC_PRIVY_APP_ID=<your-privy-app-id>In your project directory, run npm run dev. You can now visit http://localhost:3000 to see your app and login with Privy!
components/privy-provider-wrapper.tsxfor how to wrap thePrivyProviderto be explicitly client-side renderedapp/layout.tsxfor how to use your wrappedPrivyProviderin your application's Root Layoutapp/page.tsxfor how to use theusePrivyhook and implement a simpleloginbuttonapp/dashboard/page.tsxfor how to use theusePrivyhook, fields likeready,authenticated, anduser, and methods likelinkWalletandlogout
Check out our docs for more guidance around using Privy in your app!