A Next.js application integrated with Privy authentication, featuring Google sign-in and automatic wallet creation.
- Google OAuth sign-in via Privy
- Automatic embedded wallet creation for users without wallets
- Complete user and wallet data display
- Full Privy response data logging and visualization
- Support for multiple login methods (Google, Email, Wallet)
- Node.js 18+ installed
- A Privy account and App ID (Get one here)
- Go to Privy Dashboard
- Create a new app or select an existing one
- Copy your App ID from the dashboard
- In the dashboard, make sure Google is enabled as a login method:
- Go to Login Methods in your app settings
- Enable Google OAuth
Create a .env.local file in the root directory:
NEXT_PUBLIC_PRIVY_APP_ID=your_privy_app_id_hereImportant: Replace your_privy_app_id_here with your actual Privy App ID from the dashboard.
npm installnpm run devOpen http://localhost:3000 in your browser.
- User clicks "Sign In with Privy"
- Privy modal opens with login options (Google, Email, Wallet)
- User signs in with Google
- Privy automatically creates an embedded wallet in the background (if user doesn't have one)
- User data and wallet information are displayed on the page
After login, the application captures and displays:
- User Object: Contains user ID, creation date, linked accounts
- Wallet Information: Address, chain type, wallet client type, connector type
- Linked Accounts: All authentication methods linked to the user
- Google Account: Email, name, and subject from Google OAuth
All response data is:
- Logged to the browser console (check DevTools)
- Displayed in a JSON format on the page
- Available via the
usePrivyanduseWalletshooks
-
app/providers.tsx: PrivyProvider wrapper with configuration- Enables Google login
- Auto-creates wallets for users without wallets
- Configures appearance and supported chains
-
app/page.tsx: Main page component- Login/logout UI
- User information display
- Wallet information display
- Complete Privy response data visualization
The response data from Privy is available through React hooks:
import { usePrivy, useWallets } from "@privy-io/react-auth";
function MyComponent() {
const { ready, authenticated, user, login, logout } = usePrivy();
const { wallets, ready: walletsReady } = useWallets();
// Access user data
const userId = user?.id;
const userEmail = user?.google?.email || user?.email?.address;
const primaryWallet = user?.wallet?.address;
// Access connected wallets
const firstWallet = wallets[0]?.address;
}{
user: {
id: string; // Privy DID
createdAt: string; // ISO 8601 timestamp
linkedAccounts: Array; // All linked accounts
wallet: { // Primary wallet
address: string;
chainType: "ethereum" | "solana";
walletClientType: string;
connectorType: string;
};
google: { // Google OAuth data
email: string;
name: string;
subject: string;
};
};
wallets: Array; // All connected wallets
authenticated: boolean;
ready: boolean;
}You can customize Privy behavior in app/providers.tsx:
- Login Methods: Add/remove login options
- Wallet Creation: Change when wallets are created (
createOnLogin) - Appearance: Customize theme, colors, logo
- Chains: Configure supported blockchains
- Make sure
.env.localexists withNEXT_PUBLIC_PRIVY_APP_IDset - Restart the dev server after adding environment variables
- Verify Google OAuth is enabled in your Privy Dashboard
- Check that your App ID is correct
- Ensure
createOnLogin: "users-without-wallets"is set inproviders.tsx - Check browser console for any errors
- Wallet creation happens in the background and may take a few seconds